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<=个交换法则, ...
随机推荐
- Spring Boot 5 SpringSecurity身份验证
对于没有访问权限的用户需要转到登录表单页面.要实现访问控制的方法多种多样,可以通过Aop.拦截器实现,也可以通过框架实现(如:Apache Shiro.Spring Security). pom.xm ...
- MEF 松耦合
MEF天生就有解耦合的特性,虽然它不是为解耦而生,而主要是为插件类应用的开发而设计.如果主要是为了解除耦合的话可以使用IoC,Unity等. Unity 微软的IOC 代码: using System ...
- NSAttributedString
1. 使用这个类,必须先导入CoreText框架. 2. 给UILabel设置attributedText了会导致给UILabel中text,font,textColor,shadowCo ...
- Java jaxp查询节点
<?xml version="1.0" encoding="UTF-8"?> <person> <p1> <name& ...
- virtual box硬盘扩容 不是加一块硬盘
先执行 VirtualBox list hdds 查看当前 VirtualBox 管理的虚拟磁盘. 获取磁盘的 uuid. 结果如下 D:\Program Files\Oracle\VirtualBo ...
- 手动purge优化器的统计信息与AWR快照,减少对sysaux表空间的占用
1.运行以下脚本,计算当前优化器统计信息和AWR快照表占用sysaux的空间 SQL> conn / as sysdba SQL> @?/rdbms/admin/awrinfo.sql 2 ...
- java io读书笔记(3)数值类型的数据
input stream读取字节:out stream写入字节.Readers读取字符而Writers写入字符.因此,如果我们想理解input和output,我们首先就要明白 java如何处理字节,整 ...
- Swift实战-豆瓣电台(一)准备
一 准备 我们现在看看我们要做一个什么样的东西 观看地址:http://v.youku.com/v_show/id_XNzI4ODY2Mjky.html 布局 通过上面这张图我们可以看出整个demo有 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- oracle随机取数据
select * from (select rownum,KEYWORD, CATEGORY,CREATE_DATE,UPDATE_DATE from (select * from knet_keyw ...