CodeForces-740B Alyona and flowers
来源:互联网 发布:爱奇艺盒子安装软件 编辑:程序博客网 时间:2024/05/23 21:04
题目要求选择一些花的集合,如果暴力去枚举每种选择方法明显是不行的。换种方式考虑:每一个集合都能为最后的答案做出要么正的、要么负的、要么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;}
如有不当之处欢迎指出!
0 0
- 【81.82%】【codeforces 740B】Alyona and flowers
- Codeforces 740B Alyona and flowers
- CodeForces 740B - Alyona and flowers(贪心)
- 740B Alyona and flowers codeforces
- codeforces 740B Alyona and flowers
- CodeForces-740B Alyona and flowers
- CodeForces 740B Alyona and flowers 简单暴力
- Codeforces 740 B Alyona and flowers(前缀和)
- B. Alyona and flowers
- Codeforces#381(Div. 2) B.Alyona and flowers【思维+暴力】
- Codeforces Round #381 (Div. 2) B. Alyona and flowers
- Codeforces Round #209 (Div. 2) B. Alyona and flowers
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(思维题目)
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(贪心 模拟)
- Codeforces740B. Alyona and flowers
- 【CODEFORCES】 B. Pashmak and Flowers
- Codeforces Round #381 (Div. 2) A. Alyona and flowers
- Codeforces 358 . B Alyona and Mex
- Java利用反射访问私有构造函数的例子
- git rev-parse
- [FUNC]调用系统的Zip压缩功能函数
- 通过自定义编辑器在场景和资源中创建一个四边形mesh,解决plane多三角形的问题
- 电子电路学习lesson1—20161204
- CodeForces-740B Alyona and flowers
- java各技术思维导图
- vim常用命令
- Shell部分17结束
- Windows程序设计之绘制小方块
- HTML Dom节点基本用法
- 吃饭小结-161204
- matlab 工具函数(三)—— normalize(归一化数据)
- Linux切换中文后不能正确输入引号(')需要按两次才出现(‘)