http://codeforces.com/contest/733/problem/C

一道很恶心的模拟题。

注意到如果能凑成b[1],那么a的前缀和一定是有一个满足是b[1]的,因为,如果跳过了一些前面的数不用,就会剩下一个多余的东西在哪里。所以就是把a数组分成了若干段,判断每一段是否凑成b[i]了,

能凑成b[i]的条件是:

这一段a[]中,最大值的左边或者右边要有一个比它小,然后吃了它,就能吃全部了。

注意当只有1个的时候,是一定是true的。不用吃其他了,

剩下的就是恶心的模拟了,因为它的下标不断变换。

所以我就用了一个vector去存。

删除vector中的元素要用迭代器。

复杂度是O(n)的,

总体复杂度O(n*n)

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int a[maxn];
int b[maxn];
int n, k;
vector<int>arr;
struct node {
int pos;
char ch;
node() {}
node(int a, char b) : pos(a), ch(b) {}
}show[maxn];
int lenshow;
bool slove(int begin, int end, int how) {
if (begin == end) return true;
int mx = -inf;
arr.clear();
for (int i = ; i <= how; ++i) arr.push_back(inf);
for (int i = begin; i <= end; ++i) {
mx = max(mx, a[i]);
}
int pos = inf;
for (int i = begin; i <= end; ++i) {
if (a[i] == mx) {
if (i > begin && mx > a[i - ]) {
pos = i - begin + ;
break;
}
if (i < end && mx > a[i + ]) {
pos = i - begin + ;
break;
}
}
}
if (pos == inf) return false; for (int i = begin; i <= end; ++i) arr.push_back(a[i]);
vector<int> :: iterator it = arr.begin() + pos + how - ;
vector<int> :: iterator it2; int all = end - begin + ;
pos = pos + how - ;
int tbegin = how;
int tend = arr.size() - ; while (true) {
if (pos > tbegin && arr[pos] > arr[pos - ]) {
show[++lenshow] = node(pos, 'L');
arr[pos - ] += arr[pos];
it2 = it;
arr.erase(it2);
it--;
// cout << *it << endl;
pos--;
all--;
tend = arr.size() - ;
if (all == ) return true;
}
if (pos < tend && arr[pos] > arr[pos + ]) {
show[++lenshow] = node(pos, 'R');
arr[pos + ] += arr[pos];
it2 = it;
arr.erase(it2);
// cout << *it << endl;
// it = arr.begin() + how + pos - 1;
tend = arr.size() - ;
all--;
if (all == ) return true;
}
}
return true;
}
void work() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
}
scanf("%d", &k);
for (int i = ; i <= k; ++i) {
scanf("%d", &b[i]);
}
int how = ;
int begin = ;
int up = ;
for (int i = ; i <= k; ++i) {
int total = ;
bool flag = false;
int tbegin = begin;
while (begin <= n) {
total += a[begin];
if (total == b[i]) {
flag = slove(tbegin, begin, how);
up = begin;
how++;
begin++;
break;
}
begin++;
if (total > b[i]) {
printf("NO\n");
return;
}
}
if (flag == false) {
printf("NO\n");
return;
}
}
if (up != n) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
for (int i = ; i <= lenshow; ++i) {
printf("%d %c\n", show[i].pos, show[i].ch);
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

C. Epidemic in Monstropolis的更多相关文章

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

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

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

  3. Epidemic in Monstropolis

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

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

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

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

  6. codeforces733-C. Epidemic in Monstropolis 贪心加链表

    题意 现在有一个怪兽序列a[i],权值大的怪兽可以吃权值小的怪兽,吃完之后权值大的怪兽的权值会变成两者权值的和,相邻的怪兽才能吃 吃完之后,位置合并,队列前移,从左到右重新编号,重复这一过程, 然后给 ...

  7. Codeforces 733C:Epidemic in Monstropolis(暴力贪心)

    http://codeforces.com/problemset/problem/733/C 题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后, ...

  8. CodeForces 733C Epidemic in Monstropolis

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

  9. Codeforces Round #378 (Div. 2) A B C D 施工中

    A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes input ...

随机推荐

  1. PS 图像调整— — gain and bias

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); Image=im ...

  2. 用rem适配移动端

    常见方式: 1. 固定宽度(320)做法:这样前端倒是爽了,可是大页面两边有留白,小页面图标文字又会缩的很小,用户体验极其不好. 2. 流式布局:其实就是用%,这样宽度倒还差不多,高度怎么搞?所以这种 ...

  3. BZOJ4307: Maishroom & Class

    感觉有一点题面没有说得特别明确,就是一个人代替了其他人之后,另一个可以被他代替的人就不能让他来代替自己了. 每个人向自己可以代替的人连边,额外增加一个源点$r$向所有助教连边.第一问答案是$r$不能到 ...

  4. ACM学习历程—HDU5410 CRB and His Birthday(动态规划)

    Problem Description Today is CRB's birthday. His mom decided to buy many presents for her lovely son ...

  5. spring-data详解之spring-data-jpa:简单三步快速上手spring-data-jpa开发

    前言: 基于spring framework 4.x或spring boot 1.x开发环境 务必注意以下版本问题:Spring framework4.x(Spring boot1.x)对应sprin ...

  6. BZOJ1453:[WC]Dface双面棋盘

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...

  7. TCP点对点穿透探索--失败

    TCP点对点穿透探索 点对点穿透是穿透什么 点对点穿透,需要实现的是对NAT的穿透.想实现NAT的穿透,当然要先了解NAT到底是什么,以及NAT是用来干什么的.NAT全称Network Address ...

  8. Code:Base64 编码/解码

    ylbtech-Code:Base64 编码/解码 1. C#返回顶部 1.编码 byte[] inArray = new byte[msgTxt.Length]; int x; ; x < m ...

  9. java的clone()的使用

    clone()方法的约定 首先明确的是clone()是object的方法.Cloneable接口没有任何方法,它只起到标识的作用.(java的原型模式有用到) Cloneable接口的目的是作为对象的 ...

  10. Deepin安装wxpython教程

    环境: 安装报错: 解决:  1.sudo apt-get install libgtk-3-dev -y 2.sudo apt-get install freeglut3-dev libgstrea ...