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. 第十四篇 Integration Services:项目转换

    本篇文章是Integration Services系列的第十四篇,详细内容请参考原文. 简介在前一篇,我们查看了SSIS变量,变量配置和表达式管理动态值.在这一篇,我们使用SQL Server数据商业 ...

  2. 第七篇 Replication:合并复制-订阅

    本篇文章是SQL Server Replication系列的第七篇,详细内容请参考原文. 订阅服务器就是复制发布项目的所有变更将传送到的服务器.每一个发布需要至少一个订阅,但是一个发布可以有多个订阅. ...

  3. C# 模拟并发

    每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客! 当然,题外话说多了,咱进入正题! 在处理大数据的时候,经常会发生并发,并发的情况发生后,会出现数据污读,从而产生脏数据. 首 ...

  4. switch为什么不能用string类型?

    switch()括号里面的参数是一个int型值啊  你要可以转换为int型的参数才行得通啊

  5. G面经prepare: Friends Recommendation

    想想如果你用linkedin或者facebook, 给你一个人和他的朋友关系网,你会怎么给一个人推荐朋友 一个例子就是A-B, A-C, B - D, B - E, C - D,这个时候问我应该推荐谁 ...

  6. Summary: Merge Sort of Array && 求逆序对

    常用算法(后面有inplace版本): package ArrayMergeSort; import java.util.Arrays; public class Solution { public ...

  7. 数据库 CRUD

    1.删除表 drop  table +表名 2.修改表 alter  table+表名+ add(添加)+列名+ int(类型) alter  table+表名+ drop(删除)+column(列) ...

  8. oracle,sqlserver,mysql 命令行 开启、关闭所需要的服务

    ORACLE需要开启的服务   需要启动的服务:   口令: 启动Oracle 11g服务: (下面的可以作为bat 脚本,直接运行便可以不用去自己去启动和关闭服务了.) @echo off @ EC ...

  9. java dyn proxy

    package dyn; public interface RealService { void buy(); } =================== package dyn; public cl ...

  10. ANDROID模拟火花粒子的滑动喷射效果

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 年前换了一个手机,SONY的Z3C.这个手机在解锁屏幕时有一个滑动动画,类似火 ...