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(暴力贪心)的更多相关文章

  1. CodeForces 733C Epidemic in Monstropolis

    模拟. 连续的一段$a$合成一个$b$.每段中如果数字只有$1$个,那么可以合成.如果数字个数大于等于$2$个,如果都是一样的,那么无法合成,否则要找到一个可以移动的最大值位置开始移动.一开始写了一个 ...

  2. 【16.52%】【codeforces 733C】Epidemic in Monstropolis

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. CF733C Epidemic in Monstropolis[模拟 构造 贪心]

    C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Epidemic in Monstropolis

    Epidemic in Monstropolis 题目链接:http://codeforces.com/contest/733/problem/C 贪心 新序列的m个数肯定是由原序列的连续的m个子序列 ...

  8. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  9. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

随机推荐

  1. Swagger简介

    前言 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.本文简单介绍了在项目中集成swagger的方法和一些常见问题.如果想深入分析项目源码,了解更多内容,见参考资料. S ...

  2. linux 硬件信息

    1. 查看物理CPU的个数 #cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 2. 查看逻辑CPU的个数 #cat / ...

  3. c++ template怎么使用及注意事项

    c++ 中的template和c#的什么有点相似? 先看下定义方式: template <typename|class T> T myFunction(T param1,T param2. ...

  4. Dictionary中的结构体转出来

    CGRect keyBoardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

  5. PostgreSQL index types and index bloating

    warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...

  6. .NET: WPF 路由事件

    (一)使用WPF内置路由事件 xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://sc ...

  7. .NET: XML

    XML在平常生活中用得很多,它的结构很简单,跟windows explorer有点像. 对它进行操作主要有三种方式:XmlDocument, 假设有这么一个XML文件Book.XML <?xml ...

  8. ACdream 1103 瑶瑶正式成为CEO(树链剖分+费用流)

    Problem Description 瑶瑶(tsyao)是某知名货运公司(顺丰)的老板,这个公司很大,货物运输量极大,因此公司修建了许多交通设施,掌控了一个国家的交通运输. 这个国家有n座城市,公司 ...

  9. HDU 4513 吉哥系列故事——完美队形II(Manacher)

    Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...

  10. paper 23 :Kullback–Leibler divergence KL散度(2)

    Kullback–Leibler divergence KL散度 In probability theory and information theory, the Kullback–Leibler ...