Codeforces 733C:Epidemic in Monstropolis(暴力贪心)
http://codeforces.com/problemset/problem/733/C
题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后,这只怪兽的体积会变成原体积 + 吃的怪兽的体积,接下来给出 k 个怪兽的体积 bi,问能不能满足经过一系列操作后让剩下的怪兽体积变得满足下面的序列。
思路:昨晚想的时候觉得好复杂,今天补题发现实际上只有一种情况,就是每一个区间里的怪兽体积对应于一个 bi,然后拆成 k 个区间,分别找区间里面最大的去吃小的,这里可能有同时多个最大的,分别对每一种情况进行枚举,看可不可以让这个区间剩下一只怪兽,如果可以就进行下一个区间的操作,不行的话答案一定是不行的,因为前面不满足,后面就算满足了也没用。记得判一下最后分得的区间数是否刚好等于 k,在第104个test(如下)错了一发。 我觉得自己在CF或者BC中很容易给自己定个档次,就是如果AC人数不超过多少个,我觉得自己就做不出这题(难度大),但是其实这道题是完全可以弄出来的,只不过很可能卡在这104样例过不去。以后应该更加耐心,沉着,勇于挑战,不要那么浮躁。不然这样进步肯定是不大的。永远落在后面。
2
1 2
2
3 1
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
#define N 505
#define INF 0x3f3f3f3f
int sum[N], d[N], b[N], a[N], n;
typedef pair <int, int> P;
vector<P> out[N];
vector<int> vec[N];
vector<int> big, tmp; int check(int i) // 判断这个区间满足与否
{
if(sum[i] == b[i]) return ;
else if(sum[i] < b[i]) return -;
else return ;
} bool solve(int x) // 有了区间对这个区间进行判断是否可以组成 b[x]
{
for(int i = ; i <= n; i++) a[i] = d[i];
int cnt = ;
int ma = ;
big.clear();
int n = vec[x].size();
for(int i = ; i < n; i++) {
int id = vec[x][i];
if(a[id] > ma) ma = a[id];
}
for(int i = ; i < n; i++) {
int id = vec[x][i];
if(ma == a[id]) big.push_back(id);
}
int m = big.size();
int l = vec[x][], r = vec[x][n-], L, R;
for(int i = ; i < m; i++) {
L = l, R = r;
tmp.clear();
out[x].clear();
for(int j = ; j < n; j++) tmp.push_back(vec[x][j]);
int bb = big[i];
bool flag = ;
while(L < R && flag) {
// printf("bbbbb: %d\n", bb);
if(bb > L) {
if(a[bb] > a[bb-]) {
// printf("bb :%d\n", bb);
a[bb-] += a[bb];
out[x].push_back(make_pair(bb, ));
// printf("LLL\n");
bb--;
for(int i = bb + ; i <= R; i++) a[i-] = a[i];
R--;
// printf("%d %d\n", L, R);
continue;
}
}
if(bb < R) {
if(a[bb] > a[bb+]) {
// printf("bb :%d\n", bb);
a[bb] += a[bb+];
for(int i = bb + ; i <= R; i++) a[i-] = a[i];
out[x].push_back(make_pair(bb, ));
// printf("RRR\n");
R--;
// printf("%d %d\n", L, R);
continue;
}
}
flag = ;
}
if(flag) return true;
}
return false;
} int main()
{
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &d[i]);
int k;
scanf("%d", &k);
for(int i = ; i <= k; i++) scanf("%d", &b[i]);
int j = , now = ;
bool f = ;
for(int i = ; i <= n; i++) {
sum[j] += d[i];
vec[j].push_back(i);
if(check(j) == ) {
if(!solve(j)) {
f = ; break;
}
j++;
} else if(check(j) == ) {
f = ;
break;
}
}
if(!f || j != k + ) puts("NO");
else {
puts("YES");
int sum = ;
for(int i = ; i <= k; i++) { // 因为前面的被吃了,后面的要挤到前面去,所以减sum
int sz = out[i].size();
for(int j = ; j < sz; j++) {
int x = out[i][j].first - sum, y = out[i][j].second;
printf("%d %c\n", x, y == ? 'L' : 'R');
}
sum += sz;
}
}
return ;
}
Codeforces 733C:Epidemic in Monstropolis(暴力贪心)的更多相关文章
- CodeForces 733C Epidemic in Monstropolis
模拟. 连续的一段$a$合成一个$b$.每段中如果数字只有$1$个,那么可以合成.如果数字个数大于等于$2$个,如果都是一样的,那么无法合成,否则要找到一个可以移动的最大值位置开始移动.一开始写了一个 ...
- 【16.52%】【codeforces 733C】Epidemic in Monstropolis
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CF733C Epidemic in Monstropolis[模拟 构造 贪心]
C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #503 (by SIS, Div. 2) C. Elections (暴力+贪心)
[题目描述] Elections are coming. You know the number of voters and the number of parties — n and m respe ...
- Codeforces Round #378 (Div. 2) C. Epidemic in Monstropolis 模拟
C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #378 (Div. 2)-C. Epidemic in Monstropolis
C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...
- Epidemic in Monstropolis
Epidemic in Monstropolis 题目链接:http://codeforces.com/contest/733/problem/C 贪心 新序列的m个数肯定是由原序列的连续的m个子序列 ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
随机推荐
- Java数据库连接——JDBC基础知识(操作数据库:增删改查)
一.JDBC简介 JDBC是连接java应用程序和数据库之间的桥梁. 什么是JDBC? Java语言访问数据库的一种规范,是一套API. JDBC (Java Database Connectivit ...
- Install .NET Framework 4.5.2 on a Cloud Service Role
October Guest OS rollout is starting today October 15 2015, and projected to be released on November ...
- oracle导sql脚本
在plsql里,新建命令窗口,输入如下命令 @d:\test.sql
- Java基础之写文件——通过缓冲流写文件(StreamOutputToFile)
控制台程序,生成一些二进制整型值并且将它们写入到文件中. import java.nio.file.*; import java.nio.*; import java.io.*; public cla ...
- 使用Java创建RESTful Web Service
REST是REpresentational State Transfer的缩写(一般中文翻译为表述性状态转移).2000年Roy Fielding博士在他的博士论文“Architectural Sty ...
- Swift实战-小QQ(第1章):QQ登录界面
1.新建小QQ项目 2.将所需用到的图片资源(resource)文件夹,添加到项目中.并新建一个登录页面:LoginViewController.swift 3.修改LoginViewControll ...
- PostgreSQL中initdb做了什么
在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...
- 最近兰州的js风格写个插件和一个template engine
/* *@Product Name: Rational Framework Author: Calos Description: pager !important: pager */ (functio ...
- [原创]java WEB学习笔记55:Struts2学习之路---详解struts2 中 Action,如何访问web 资源,解耦方式(使用 ActionContext,实现 XxxAware 接口),耦合方式(通过ServletActionContext,通过实现 ServletRequestAware, ServletContextAware 等接口的方式)
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- android命令安装apk时报错:INSTALL_FAILED_CPU_ABI_INCOMPATIBLE
点击下载Genymotion-ARM-Translation.zip 将你的虚拟器运行起来,将下载好的zip包用鼠标拖到虚拟机窗口中,出现确认对跨框点OK就行.然后重启你的虚拟机.