bzoj3412: [Usaco2009 Dec]Music Notes乐谱
2017-07-06 18:57
453 查看
前缀和+二分。有很多做法
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[50005]; int find(int x,int l,int r) { int mid=l+r>>1; if(l==r) { return r; } else if(a[mid]==x) return mid; if(a[mid]>x) return find(x,l,mid); else return find(x,mid+1,r); } int main() { int n,x,q,t; cin>>n>>q; for(int i=1;i<=n;i++) { scanf("%d",&x); a[i]=a[i-1]+x; } for(int i=1;i<=q;i++) { scanf("%d",&t); printf("%d\n",find(t+1,1,n)); } }
相关文章推荐
- 【BZOJ】3412: [Usaco2009 Dec]Music Notes乐谱(二分)
- BZOJ 3412: [Usaco2009 Dec]Music Notes乐谱(离线处理)
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- BZOJ3412: [Usaco2009 Dec]Music Notes乐谱
- BZOJ——3412: [Usaco2009 Dec]Music Notes乐谱
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者(贪心)
- bzoj3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
- bzoj1774 [Usaco2009 Dec]Toll 过路费
- bzoj 1774: [Usaco2009 Dec]Toll 过路费 ——(改)floyd
- [贪心]BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者
- 【BZOJ】3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者(贪心)
- BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者 离散化dp
- [floyed 增量 离线] BZOJ 1774 [Usaco2009 Dec]Toll 过路费
- BZOJ3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者
- BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd
- [BZOJ] 1775: [Usaco2009 Dec]Vidgame 电视游戏问题
- bzoj3411 [Usaco2009 Dec]Bobsledding 高山滑雪
- 【BZOJ】1774: [Usaco2009 Dec]Toll 过路费
- bzoj1774【Usaco2009 Dec】Toll 过路费