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. Android --ListView使用ArrayAdapter

    1.继承ArrayAdapter public class TimerDataAdapter extends ArrayAdapter<TimerDataListItem> { //数据I ...

  2. [SharpMap]二叉树索引

    读取shp文件建立二叉树索引的基本思路分析: /// <summary> /// Generates a spatial index for a specified shape file. ...

  3. 读取plist

    - (NSArray *)imageData { if (_imageData == nil) { // 从未初始化 // 初始化数据 // File : 全路径 // NSBundle : 一个NS ...

  4. 汉字拼音带声调和发音mp3文件(C#源程序)

    7800多个汉字的拼音带声调以及全部mp3读音文件,附带一个C#实例程序源代码 读音文件按拼音和声调命名,方便调用 获取全部源代码

  5. instruments 教程

    https://www.raywenderlich.com/97886/instruments-tutorial-with-swift-getting-started

  6. css背景图片拉伸 以及100% 满屏显示

    如何用css背景图片拉伸 以及100% 满屏显示呢?这个问题听起来似乎很简单.但是很遗憾的告诉大家.不是我们想的那么简单. 比如一个容器(body,div,span)中设定一个背景.这个背景的长宽值在 ...

  7. Nand Flash与Nor Flash的区别

    区别:http://zhidao.baidu.com/question/1068445.html?qbl=relate_question_0&word=Serial%20Flash%20%D3 ...

  8. Effective C++ 1.让自己习惯C++

    //条款01:视C++为一个语言联邦 // 1:C++主要包含的语言为: // A:C.说到底C++仍然以C为基础.区块(blocks).语句.预处理器.内置数据类型.数组.指针等均来自于C.许多时候 ...

  9. Leetcode: Implement Trie (Prefix Tree) && Summary: Trie

    Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs a ...

  10. PHP isset()与empty()的使用区别详解

    通过对PHP语言的学习,应该知道它是基于函数的一款HTML脚本语言.庞大的函数库支持着PHP语言功能的实现.下面我们为大家介绍有关PHP函数isset()与empty()的相关用法.   PHP的is ...