TOJ 2596: Music Notes
2596: Music Notes 
Total Submit: 3 Accepted:3
Description
FJ is going to teach his cows how to play a song. The song consists of N (1 ≤ N ≤ 100) notes, and the i-th note lasts for B_i (1 ≤ B_i ≤ 100) beats. The cows will begin playing the song at time 0; thus, they will play note 1 from time 0 to time B_1 - 1, note 2 fromtime B_1 to time B_1 + B_2 - 1, etc.
The cows have lost interest in the song, as they feel that it is long and boring. Thus, to make sure his cows are paying attention, FJ asks them Q (1 ≤ Q ≤ 1,000) questions of the form, "During the beat at time T_i (0 ≤ T_i < length of song), which note should you be playing?" The cows need your help to answer these questions.
By way of example, consider a song with these specifications: note 1 for length 2, note 2 for length 1, and note 3 for length 3:
NOTES 1 1 2 3 3 3
+---+---+---+---+---+---+
TIME 0 1 2 3 4 5
Input
* Line 1: Two space-separated integers: N and Q
* Lines 2..N+1: Line i+1 contains a single integer: B_i
* Lines N+2..N+Q+1: Line N+i+1 contains a single integer: T_i
Output
* Lines 1..Q: Line i contains the a single integer that is the note the cows should be playing at time T_i
Sample Input
3 5
2
1
3
2
3
4
0
1
Sample Output
2
3
3
1
1
这么简单的题怎么没有人写题解,你有n首歌,问你可以听到第几首,前缀和处理下,然后二分直接输出啊
#include<stdio.h>
int a[],n,q;
int BS(int x)
{
int l=,r=n;
while(l<=r)
{
int mi=(l+r)/;
if(a[mi]>x)r=mi-;
else l=mi+;
}
return l;
}
int main()
{
while(~scanf("%d%d",&n,&q))
{
scanf("%d",&a[]);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]+=a[i-];
}
while(q--)
{
int x;scanf("%d",&x);
printf("%d\n",BS(x));
}
}
return ;
}
原题数据范围应该很大,这个暴力复杂度都还正常
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[],n,q;
int main()
{
while(~scanf("%d%d",&n,&q))
{
scanf("%d",&a[]);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]+=a[i-];
}
while(q--)
{
int x;scanf("%d",&x);
printf("%d\n",(int)(upper_bound(a+,a+n+,x)-a));
}
}
return ;
}
TOJ 2596: Music Notes的更多相关文章
- ASP.NET Core 1.1.0 Release Notes
ASP.NET Core 1.1.0 Release Notes We are pleased to announce the release of ASP.NET Core 1.1.0! Antif ...
- Android Weekly Notes Issue #237
Android Weekly Issue #237 December 25th, 2016 Android Weekly Issue #237 这是本年的最后一篇issue, 感谢大家. 本期内容包括 ...
- Android Weekly Notes Issue #230
Android Weekly Notes Issue #230 November 6th, 2016 Android Weekly Issue #230. Android Weekly笔记, 本期内容 ...
- Android Weekly Notes Issue #229
Android Weekly Issue #229 October 30th, 2016 Android Weekly Issue #229 Android Weekly笔记, 本期内容包括: 性能库 ...
- Android Weekly Notes Issue #227
Android Weekly Issue #227 October 16th, 2016 Android Weekly Issue #227. 本期内容包括: Google的Mobile Vision ...
- Android Weekly Notes Issue #221
Android Weekly Issue #221 September 4th, 2016 Android Weekly Issue #221 ARTICLES & TUTORIALS And ...
- Android Weekly Notes Issue #219
Android Weekly Issue #219 August 21st, 2016 Android Weekly Issue #219 ARTICLES & TUTORIALS Andro ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
随机推荐
- Perl的Notepad++环境配置
Notepad++打开pl文件F5录入命令分别保存. Run_Perl(F9): cmd /k F:\Strawberry\perl\bin\perl.exe -w "$(FULL_CURR ...
- Android Studio项目上传到Jcenter
一.将你要发布的moudle的build.gradle中添加代码,gradle的最后添加 PUBLISH_GROUP_ID = 'com.zzti.fengyongge' PUBLISH_ARTIFA ...
- React Native 手工搭建环境 之iOS篇
常识 React native 开发服务器 在开发时,我们的框架是这样的:  当正式发布进入到生产环境时,开发服务器上所有的js文件将会被编译成包的形式,直接嵌入到客户端内.这时,已经不再需要开发服 ...
- MySQL索引使用等
- HDU 1693 Eat the Trees (插头DP)
题意:给一个n*m的矩阵,为1时代表空格子,为0时代表障碍格子,问如果不经过障碍格子,可以画一至多个圆的话,有多少种方案?(n<12,m<12) 思路: 这题不需要用到最小表示法以及括号表 ...
- COGS 133. [USACO Mar08] 牛跑步
★★★ 输入文件:cowjog.in 输出文件:cowjog.out 简单对比时间限制:1 s 内存限制:128 MB Bessie准备用从牛棚跑到池塘的方法来锻炼. 但是因为她懒,她 ...
- iOS面试题 第一天
今天上午,下午分别面试了两家公司.上午是一家互联网公司,气氛还比较好,是我比较喜欢的.技术这块是直接机试,主要是给了些BUG让我修复,整个过程还算顺利.下午去了一家大型的证券公司.整理技术问题如下: ...
- BestCoder Round#15 1001-Love
http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others) Memory ...
- java 一个对象多少大,占用多少内存
1.instrumentation这种方法还是靠谱的 一个对象占用多少字节? 2.sizeof库 <!-- https://mvnrepository.com/artifact/com.carr ...
- qemu-img管理虚拟机
qemu-img管理虚拟机 1. 查看正在运行的虚拟机 [root@idca-vm02 ~]# virsh list Id 名称 状态 ----- ...