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的更多相关文章

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

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

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

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

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

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

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

  7. CodeForces 733C Epidemic in Monstropolis

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

  8. C. Epidemic in Monstropolis

    http://codeforces.com/contest/733/problem/C 一道很恶心的模拟题. 注意到如果能凑成b[1],那么a的前缀和一定是有一个满足是b[1]的,因为,如果跳过了一些 ...

  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. iframe跨域通讯

    工作中遇到一个问题,IFRAME嵌套了一个外部页面用于统计 统计的JS由我们提供,并且需要提供热点图 一开始就碰到的问题就是 不知道页面高度 需要子页面传回页面高度用于将IFRAME拉升到合适高度 当 ...

  2. angular 实战系列 之 mvvm模式

    什么是MVVM模式 mvvm模式是mvc模式的一种变体,其中第一个m表示model,可以认为是数据对象的抽象,v代表view,vm代表view model ,是对view中的数据抽象(注1).mvvm ...

  3. A2D规则引擎

    A2D规则引擎 写了个简单的规则引擎,普通情况够用了: 比如2家公司有各自的利率计算规则,如下: 在C#方面,没有写在C#的业务逻辑代码中,而是移到了外部规则文件中,如(ACompanyRatePol ...

  4. JS中for循序中延迟加载实现动态效果

    JS中for循序中延迟加载实现动态效果 今天在做一个前端的效果的时候碰到一个棘手的问题,就是实现一个动态的圆柱效果,废话不多少,直接上代码. <script src="js/jquer ...

  5. (Sql Server)数据的拆分和合并

    (Sql Server)数据的拆分和合并 背景: 今天遇到了数据合并和拆分的问题,尝试了几种写法.但大致可分为两类:一.原始写法.二.Sql Server 2005之后支持的写法.第一种写法复杂而且效 ...

  6. Microsoft 2013校园招聘笔试题及解答

    Microsoft 2013校园招聘笔试题及解答 题目是自己做的,求讨论.吐槽.拍砖 1.      Which of the following callingconvension(s) suppo ...

  7. 常用PHP正则表达式

    获取所有图片网址preg_match_all(“/ src=(\”|\’){0,}(http:\/\/(.+?))(\”|\’|\s|>)/is”,$text,$img); 匹配中文字符的正则表 ...

  8. nginx+apache+mysql+php+memcache+squid搭建集群web环境

    服务器的大用户量的承载方案 一.前言 二.编译安装 三. 安装MySQL.memcache 四. 安装Apache.PHP.eAccelerator.php-memcache 五. 安装Squid 六 ...

  9. hdu 1998 奇数阶魔方(找规律+模拟)

    应该不算太水吧. 17  24   1   8  15   23   5   7  14  16    4   6  13  20  22   10  12  19  21   3   11  18 ...

  10. Hexo+NextT第三方服务调用【4】

    该系列博客列表请访问:http://www.cnblogs.com/penglei-it/category/934299.html 摘要        静态站点与动态站点有很大的不一样,它拥有一定的局 ...