CodeForces-740B Alyona and flowers
题目要求选择一些花的集合,如果暴力去枚举每种选择方法明显是不行的。换种方式考虑:每一个集合都能为最后的答案做出要么正的、要么负的、要么0贡献,先把所有集合能做出的贡献预处理,然后从m个集合里面选择贡献为正的即可。
AC代码:
#include<cstdio>
const int maxn=100+5;
struct node{
int l,r;
int ans;
}b[maxn];
int a[maxn];
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
for(int i=0;i<m;++i){
b[i].ans=0;
scanf("%d%d",&b[i].l,&b[i].r);
for(int j=b[i].l;j<=b[i].r;++j)
b[i].ans+=a[j];
}
int aa=0;
for(int i=0;i<m;++i){
if(b[i].ans>0) aa+=b[i].ans;
}
printf("%d\n",aa);
}
return 0;
}
如有不当之处欢迎指出!
CodeForces-740B Alyona and flowers的更多相关文章
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- Codeforces 451E Devu and Flowers(容斥原理)
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...
- Alyona and flowers
Alyona and flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces Round #340 Watering Flowers
题目: http://www.codeforces.com/contest/617/problem/C 自己感觉是挺有新意的一个题目, 乍一看挺难得(= =). 其实比较容易想到的一个笨办法就是:分别 ...
- codeforces 682C Alyona and the Tree(DFS)
题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...
随机推荐
- python字符串问题
相关知识点: 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unico ...
- MTF 曲线图解读
最近想入手佳能小小白(EF70-200 F4.0 USM),购买镜头的时候,在镜头厂商的产品页看到下面形状的曲线图: 这是什么意思呢?看着很复杂的样子啊?百度了一圈学习了一下,下面做个简单的分析. 这 ...
- Java常用代码总结
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/7004474.html 1.日期与字符串之间的转换 public static void m ...
- ASP.NET没有魔法——ASP.NET MVC 模型验证
在前面的文章中介绍了用户的注册及登录功能,在注册用户时可以通过代码的形式限制用户名及密码的格式,如果不符合要求那么就无法完成操作,如下图: 该功能的原理是Identity基于的Entity Frame ...
- TensorflowTutorial_一维数据构造简单CNN
使用一维数据构造简单卷积神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 神经网络对于一维数据非常重要,时序数据集.信号处理数据集和一些文本嵌入数据集都是一维数据,会频繁的使用到神经网 ...
- 00_Python面试题_迭代更新
一.Python是什么类型的语言,以及和其他语言对比 1.Python是一种解释性语言,他和C语言以及C衍生的语言不通,在Python运行之前不需要编译,其他解释语言还有Ruby.PHP. 2.Pyt ...
- Object Detection · RCNN论文解读
转载请注明作者:梦里茶 Object Detection,顾名思义就是从图像中检测出目标对象,具体而言是找到对象的位置,常见的数据集是PASCAL VOC系列.2010年-2012年,Object D ...
- Animations and transitions
在交互式可视化中,有一个词叫reactive,指的是以可视化的方式来响应用户的行为,帮助用户进行可视化并理解其结果.这个很有用.那如何来实现这种交互呢?通过动画. 如果处理得当,动画可以展现出不错的可 ...
- javascript 中 dom.getAttribute("value") 与dom.value的差异
dom 是一个 input type="text" 手动修改 input 的值, 使用 dom.getAttribute("value") 只能得到 html ...
- cnpm,vue等命令不识别的问题废人解决方案
关于安装的cnpm,vue等不识别的问题 我想了很久然后再网上看了一些教程发现添加系统变量Path没什么用 我就在用户变量里面添加的,完美解决问题 在我的电脑右键->属性->高级系统设置- ...