bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
来源:互联网 发布:分组密码算法 编辑:程序博客网 时间:2024/05/17 03:36
→题目链接←
维护前缀和,对于每次询问找到第一个大于它的数(也就是upper_bound)的下标,就是答案
手写可以二分找
用stl可以用upper_bound
代码:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int n,m;int sum[50050];int main(){scanf("%d%d",&n,&m);for(int i=1; i<=n; i++){scanf("%d",&sum[i]);sum[i]+=sum[i-1];}while(m--){int x;scanf("%d",&x);printf("%d\n",upper_bound(sum+1,sum+1+n,x)-sum);}return 0;}
阅读全文
0 0
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- bzoj3412 [Usaco2009 Dec]Music Notes乐谱
- bzoj3412: [Usaco2009 Dec]Music Notes乐谱
- USACO 2009 Dec Silver 2.Music Notes
- 【BZOJ 1774】 [Usaco2009 Dec]Toll 过路费
- Bzoj 1774 [Usaco2009 Dec]Toll 过路费
- BZOJ 1774 [Usaco2009 Dec] Toll 过路费
- (bzoj 1774 [Usaco2009 Dec]Toll 过路费)
- BZOJ 1775 [Usaco2009 Dec] Vidgame 电视游戏问题
- [贪心] BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
- BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者 离散化dp
- [贪心]BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者
- BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者 贪心
- bzoj1774【Usaco2009 Dec】Toll 过路费
- bzoj1774 [Usaco2009 Dec]Toll 过路费
- Flat - Music scores and guitar tabs editor(乐谱编辑器)
- 乐谱
- ThreeJs之四大组件
- kotlin+Rxjava+retrofit搭建MVP模式
- UVA
- RMQ问题——ST算法
- 290
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- 判断平行四边形数(typedef pair<int,int> p;)
- 291
- 根据的xc5683同志的测试人员sql必知必会总结的笔记
- 292
- Kotlin开发必备知识
- 293
- OTP动态密码_Java代码实现
- 294