CodeForces 733C Epidemic in Monstropolis
模拟。
连续的一段$a$合成一个$b$。每段中如果数字只有$1$个,那么可以合成。如果数字个数大于等于$2$个,如果都是一样的,那么无法合成,否则要找到一个可以移动的最大值位置开始移动。一开始写了一个模拟,没考虑到严格大于,$WA$在$106$组数据了......
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} int n,k;
long long a[],b[];
vector<int>p,op; int main()
{
cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
cin>>k;
for(int i=;i<=k;i++) cin>>b[i]; long long sum=;
int pos=,pre=,fail=; for(int i=;i<=n;i++)
{
sum=sum+a[i];
if(sum<b[pos]) continue;
else if(sum>b[pos]) {fail=; break;}
else
{
if(i-pre==)
{
pos++; sum=; pre=i;
continue;
} bool d=;
for(int j=pre+;j<i;j++) if(a[j]!=a[j+]) d=;
if(d==) {fail=; break;} long long mx=; int idx;
for(int j=pre+;j<=i;j++) mx=max(mx,a[j]); for(int j=pre+;j<=i;j++)
{
if(a[j]!=mx) continue;
if(j->=pre+&&a[j-]!=mx)
{
idx=j;
for(int t=;t<=idx-pre-;t++) { p.push_back(idx-pre+pos--t+); op.push_back(); }
for(int t=;t<=i-idx+-;t++) { p.push_back(pos); op.push_back(); }
break;
} else if(j+<=i&&a[j+]!=mx)
{
idx=j;
for(int t=;t<=i-idx+-;t++) { p.push_back(idx-pre+pos-); op.push_back(); }
for(int t=;t<=idx-pre-;t++) { p.push_back(idx-pre+pos--t+); op.push_back(); }
break;
} } pos++; sum=; pre=i;
}
} if(pos!=k+) fail=; if(fail==) printf("NO\n");
else
{
printf("YES\n");
for(int i=;i<p.size();i++)
{
cout<<p[i]<<" ";
if(op[i]==) cout<<"L";
else cout<<"R";
cout<<endl;
}
} return ;
}
CodeForces 733C Epidemic in Monstropolis的更多相关文章
- 【16.52%】【codeforces 733C】Epidemic in Monstropolis
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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个子序列 ...
- CF733C Epidemic in Monstropolis[模拟 构造 贪心]
C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 733C:Epidemic in Monstropolis(暴力贪心)
http://codeforces.com/problemset/problem/733/C 题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后, ...
- C. Epidemic in Monstropolis
http://codeforces.com/contest/733/problem/C 一道很恶心的模拟题. 注意到如果能凑成b[1],那么a的前缀和一定是有一个满足是b[1]的,因为,如果跳过了一些 ...
- codeforces733-C. Epidemic in Monstropolis 贪心加链表
题意 现在有一个怪兽序列a[i],权值大的怪兽可以吃权值小的怪兽,吃完之后权值大的怪兽的权值会变成两者权值的和,相邻的怪兽才能吃 吃完之后,位置合并,队列前移,从左到右重新编号,重复这一过程, 然后给 ...
- 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 ...
随机推荐
- Codeforces 617E XOR and Favorite Number莫队
http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...
- [Luogu 2261] CQOI2007 余数求和
[Luogu 2261] CQOI2007 余数求和 这一定是我迄今为止见过最短小精悍的省选题了,核心代码 \(4\) 行,总代码 \(12\) 行,堪比小凯的疑惑啊. 这题一看暴力很好打,然而 \( ...
- 「6月雅礼集训 2017 Day11」jump
[题目大意] 有$n$个位置,每个位置有一个数$x_i$,代表从$i$经过1步可以到达的点在$[\max(1, i-x_i), \min(i+x_i, n)]$中. 定义$(i,j)$的距离表示从$i ...
- 虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点
虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点 https://www.evernote.com/shard/s22 ...
- Computer(HDU2196+树形dp+树的直径)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2196 题目: 题意:有n台电脑,每台电脑连接其他电脑,第i行(包括第一行的n)连接u,长度为w,问你每 ...
- httpd -v command not found
使用 find / -name "apachectl"查找文件目录下执行 ./apachectl -v
- Git 常用命令(二)
用 git init 在目录中创建新的 Git 仓库. $ mkdir test $ cd test/ $ git init Initialized empty Git repository in ...
- 重拾Object--(一)初识
Java中的Object类有着特殊的意义,他是所有其它类的父类,查看Object类的源代码,可以发现代码不多,逻辑也很简单. Java所有类的源代码我们都可以在JDK的文件中查看,在JDK下会有一个名 ...
- [Leetcode Week16]Insertion Sort List
Insertion Sort List 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/insertion-sort-list/description/ ...
- 命令行创建KVM虚拟机
qemu命令创建虚拟机: qemu-img create -f qcow2 /home/ubuntu.img 20G qemu-system-x86_64 -m 2048 -enable-kvm ...