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和其整个子树都将被删去,求被 ...
随机推荐
- scrapy_xpath
什么是xpath? 路径表达式 在xml和html中进行导航 包含标准函数库 遵循w3c标准 xpth节点关系是什么? 父节点 子节点 兄弟节点 先辈节点 后代节点 xpth语法 a ...
- junit源码解析--捕获测试结果
OK,前面的博客我们整理了junit运行完了所有的测试用例,那么OK了,现在开始该收集测试结果了. 在这最后一步中,junit主要是玩一个类,TestResult.这里类中封装了几个参数,在初始化这个 ...
- jdbc与java.sql
JDBC连接操作数据库流程:1.将数据库驱动jar包放在lib文件夹下. 2.定义驱动名(driver),数据库url,username,password字符串常量 3.注册数据库驱动Class.fo ...
- 通俗易懂的分析如何用Python实现一只小爬虫,爬取拉勾网的职位信息
源代码:https://github.com/nnngu/LagouSpider 效果预览 思路 1.首先我们打开拉勾网,并搜索"java",显示出来的职位信息就是我们的目标. 2 ...
- 一步一步从原理跟我学邮件收取及发送 9.多行结果与socket的阻塞
前几篇的文章发表后,有网友留言说没有涉及到阻塞的问题吗?在 socket 的编程当中,这确实是个很重要的问题.结合目前我们文章的内容进度,我们来看看为什么说阻塞概念很重要. 接着上篇的内容,当我们发送 ...
- python使用上下文管理器实现sqlite3事务机制
如题,本文记录如何使用python上下文管理器的方式管理sqlite3的句柄创建和释放以及事务机制. 1.python上下文管理(with) python上下文管理(context),解决的是这样一类 ...
- 不免费的PacMan
课程内容介绍: 本套课程适合以下人士: - 免费资料没教会你游戏开发的: - 学了Unity基础不知道怎么用在游戏项目里的: - 想快速开发一款好玩的游戏的: - 想学游戏不知道如何入门的: - 对游 ...
- python中的线程之semaphore信号量
semaphore是一个内置的计数器 每当调用acquire()时,内置计数器-1 每当调用release()时,内置计数器+1 计数器不能小于0,当计数器为0时,acquire()将阻塞线程直到其他 ...
- bzoj 2095: [Poi2010]Bridges [混合图欧拉回路]
2095: [Poi2010]Bridges 二分答案,混合图欧拉路判定 一开始想了一个上下界网络流模型,然后发现不用上下界网络流也可以 对于无向边,强制从\(u \rightarrow v\),计算 ...
- bzoj 1930: [Shoi2003]pacman 吃豆豆 [费用流]
1930: [Shoi2003]pacman 吃豆豆 题意:两个PACMAN吃豆豆.一开始的时候,PACMAN都在坐标原点的左下方,豆豆都在右上方.PACMAN走到豆豆处就会吃掉它.PACMAN行走的 ...