Epidemic in Monstropolis
Epidemic in Monstropolis
题目链接:http://codeforces.com/contest/733/problem/C
贪心
新序列的m个数肯定是由原序列的连续的m个子序列构成的,只需要找到每个连续子序列中最大的数即可。
细节中需要注意:一个连续子序列可能有很多个最大数,最大数的左右两个数必须要有一个小于这个数;还有下标的处理。
代码如下:
import sys n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()] sum1,sum2 = 0,0
for i in a:
sum1 += i
for i in b:
sum2 += i if sum1 != sum2:
print('NO')
sys.exit(0) s = []
idx = 0
for i in range(m):
t = b[i]
oo = idx
mm = idx while t > 0:
t -= a[idx]
if a[mm] < a[idx]:
mm = idx
idx += 1
if t < 0:
print('NO')
sys.exit(0) if mm == oo:
while mm+1<idx and a[mm]==a[mm+1]:
mm = mm+1 flag = 0
if mm-1>=oo and a[mm]>a[mm-1]:
flag = 1
elif mm+1<idx and a[mm]>a[mm+1]:
flag = 2
elif idx-oo == 1:
continue if flag == 0:
print('NO')
sys.exit(0)
elif flag == 1:
for x in range(mm,oo,-1):
s.append([x-oo+i,'L'])
for x in range(mm,idx-1):
s.append([i,'R'])
elif flag == 2:
for x in range(mm,idx-1):
s.append([mm-oo+i,'R'])
for x in range(mm,oo,-1):
s.append([x-oo+i,'L']) print('YES')
for x in s:
print(x[0]+1,x[1])
Epidemic in Monstropolis的更多相关文章
- CF733C 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 ...
- 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 ...
- 【16.52%】【codeforces 733C】Epidemic in Monstropolis
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- codeforces733-C. Epidemic in Monstropolis 贪心加链表
题意 现在有一个怪兽序列a[i],权值大的怪兽可以吃权值小的怪兽,吃完之后权值大的怪兽的权值会变成两者权值的和,相邻的怪兽才能吃 吃完之后,位置合并,队列前移,从左到右重新编号,重复这一过程, 然后给 ...
- Codeforces 733C:Epidemic in Monstropolis(暴力贪心)
http://codeforces.com/problemset/problem/733/C 题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后, ...
- CodeForces 733C Epidemic in Monstropolis
模拟. 连续的一段$a$合成一个$b$.每段中如果数字只有$1$个,那么可以合成.如果数字个数大于等于$2$个,如果都是一样的,那么无法合成,否则要找到一个可以移动的最大值位置开始移动.一开始写了一个 ...
- C. Epidemic in Monstropolis
http://codeforces.com/contest/733/problem/C 一道很恶心的模拟题. 注意到如果能凑成b[1],那么a的前缀和一定是有一个满足是b[1]的,因为,如果跳过了一些 ...
- 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 ...
随机推荐
- 一致性hash和虚拟节点
consistent hashing 算法的原理 consistent hashing 是一种 hash 算法,简单的说,在移除 / 添加一个 cache 时,它能够尽可能小的改变已存在key 映射关 ...
- net破解一(反编译,反混淆-剥壳,工具推荐)
net破解一(反编译,反混淆-剥壳,工具推荐) 大家好,前段时间做数据分析,需要解析对方数据,而数据文件是对方公司内部的生成方式,完全不知道它是怎么生成的. 不过还好能拿到客户端(正好是C#开发)所以 ...
- CSS sprites减少HTTP请求
使用CSS sprites减少HTTP请求 sprites是鬼怪,小妖精,调皮鬼的意思,初听这个高端洋气的名字我被震慑住了,一步步掀开其面纱后发觉很简单的东西,作用却很大 神马是CSS 小妖精 C ...
- 企业架构研究总结(43)——企业架构与建模之ArchiMate详述(下)
2.7 关系模型元素 企业架构模型包括了各种概念元素以及他们之间的关系,这其中的概念元素已经在前面几节中进行了阐述,而这些概念元素之间的关系则是本节的叙述重点.虽然ArchiMate中具有种类繁多的概 ...
- Single Image Haze Removal Using Dark Channel Prior
<Single Image Haze Removal Using Dark Channel Prior>一文中图像去雾算法的原理.实现.效果及其他. Posted on 2013-08-2 ...
- java并发之固定对象与实例
java并发之固定对象与实例 Immutable Objects An object is considered immutable if its state cannot change after ...
- kivy EventDispatcher
Let's talk about kivy's EventDispatcher here: The codes I have tried here: codes here: from kivy.eve ...
- mmap学习
mmap学习 内存页: Linux是以页为单位来管理物理内存的,一页大小一般等于4096字节.页容量越大,系统中可能存在的内存碎片就越多. mmap将一个磁盘上的文件或者对象映射进内存.文件被映射到多 ...
- 手动创建servlet
1 tomcat/webapps/目录下创建web应用mail. 目录结构如下 tomcat/webapps | mail | WEB-INF | | ...
- QT 菜单程序
MainWindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include<QMainWindow> #include<QMess ...