洛谷 P2969 [USACO09DEC]音符Music Notes
题目描述
FJ is going to teach his cows how to play a song. The song consists of N (1 <= N <= 50,000) notes, and the i-th note lasts for B_i (1 <= B_i <= 10,000) beats (thus no song is longer than 500,000,000 beats). The cows will begin playing the song at time 0; thus, they will play note 1 from time 0 through just before time B_1, note 2 from time B_1 through just before time B_1 + B_2, etc.
However, recently the cows have lost interest in the song, as they feel that it is too long and boring. Thus, to make sure his cows are paying attention, he asks them Q (1 <= Q <= 50,000) questions of the form, 'In the interval from time T through just before time T+1, which note should you be playing?' The cows need your help to answer these questions which are supplied as T_i (0 <= T_i <=
end_of_song).
Consider this song with three notes of durations 2, 1, and 3 beats:
Beat: 0 1 2 3 4 5 6 ...
|----|----|----|----|----|----|--- ...
1111111111 : :
22222: :
333333333333333:
Here is a set of five queries along with the resulting answer:
Query Note
2 2
3 3
4 3
0 1
1 1
约翰准备教他的奶牛们弹一首歌.这首歌由N(1<=n<= 50000)个音阶组成,第i个音阶要敲 击Bi<=10000次.奶牛从第0时刻开始弹,因此他从0时刻到Bi-1时刻都是敲第1个音阶, 然后他从B1时刻到B1+B2-1时刻敲第2个音阶,从B1+B2到B1+B2+B3-1时刻敲第3个 音阶……现在有q(i<q<50000)个问题:在时间段区间t,T+1内,奶牛敲的是哪个音阶?
输入输出格式
输入格式:
Line 1: Two space-separated integers: N and Q
Lines 2..N+1: Line i+1 contains the single integer: B_i
- Lines N+2..N+Q+1: Line N+i+1 contains a single integer: T_i
输出格式:
- Lines 1..Q: For each query, print a single integer that is the index of the note that the cows should be playing.
输入输出样例
3 5
2
1
3
2
3
4
0
1
2
3
3
1
1
思路:二分
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,q;
int l,r,mid;
int b[],num[];
int main(){
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
num[i]=num[i-]+b[i];
}
for(int i=;i<=q;i++){
int x;
scanf("%d",&x);
l=;r=n;
while(l<=r){
mid=(l+r)/;
if(num[mid]<=x) l=mid+;
else r=mid-;
}
cout<<l<<endl;
}
}
洛谷 P2969 [USACO09DEC]音符Music Notes的更多相关文章
- [USACO09DEC]音符Music Notes (二分、STL)
https://www.luogu.org/problem/P2969 题目描述 FJ is going to teach his cows how to play a song. The song ...
- 洛谷 P2970 [USACO09DEC]自私的放牧Selfish Grazing
P2970 [USACO09DEC]自私的放牧Selfish Grazing 题目描述 Each of Farmer John's N (1 <= N <= 50,000) cows li ...
- 洛谷P2017 [USACO09DEC]晕牛Dizzy Cows [拓扑排序]
题目传送门 晕牛Dizzy Cows 题目背景 Hzwer 神犇最近又征服了一个国家,然后接下来却也遇见了一个难题. 题目描述 The cows have taken to racing each o ...
- 洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...
- [洛谷P2048] [NOI2010] 超级钢琴
洛谷题目链接:[NOI2010]超级钢琴 题目描述 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号 ...
- 洛谷 P2614 计算器弹琴
P2614 计算器弹琴 题目描述 总所周知,计算器可以拿来干很多它本不应该干的事情,比如写作文.(参看洛谷P2549) 小A发现了一个计算器的另一个隐藏功能——弹琴. http://www.bilib ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
随机推荐
- jq 监听键盘事件
其实这个也是挺简单的一些东西.也就是几个参数: 一.首先需要知道的是: 1.keydown() keydown事件会在键盘按下时触发. 2.keyup( ...
- 洛谷 P2684 搞清洁
P2684 搞清洁 题目描述 FJ准备分配它的N只奶牛(1 <= N <= 25,000) 做清洁工作,他把一天分成T(1 <= T <= 1,000,000)个时间段,他希望 ...
- cogs 26. 分组
26. 分组 ★ 输入文件:dataa.in 输出文件:dataa.out 简单对比时间限制:1 s 内存限制:128 MB[问题描述] 现有 n 个学生, 要分成X1 ,X2 ,.. ...
- ListView-添加head跟foot item 问题
今天在使用ListView 的 addFooterView 的方法时候,遇到了一个问题.当我代码中执行了如下的操作 ListView listView = new ListView(this); li ...
- js中常用的对象—Math的属性和方法
js中有一个内置对象——Math对象,在有的时候非常有用,我们来分析一下: Math常用属性(注意要大写): E 返回算术常量 e,即自然对数的底数(约等于2.718)LN2 返回 2 的自然对数(约 ...
- asp.net大数据导出execl实现分开压缩并下载
asp.net大数据导出execl实现分开压缩并下载 /// <summary> /// 导出数据到EXCEL 多个表的 /// </summary> /// <para ...
- 项目融入mongoDB
1.pom.xml导入jar包 <!-- mongoDB --> <dependency> <groupId> ...
- tomcat:web容器
Web容器和应用服务器除了你所说的request response之外还有很多其他重要的功能. 1. 多线程和并发处理,估计你写的socket程序支持不了几个并发访问吧 2. 安全性 3. 生命周期管 ...
- Summary Day32
1 . 文件管理 1.1 标C文件处理和UC文件处理函数的比較: 标C文件处理函数比UC的文件处理函数速度快.由于标C内部独立输入输出缓冲区, 会积累一定数量之后再写入文件,因此读写效率比較高 使用t ...
- [TypeScript] Make Properties and Index Signatures Readonly in TypeScript
TypeScript 2.0 introduced the readonly modifier which can be added to a property or index signature ...