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 ...
随机推荐
- 如何设置文件审计软件FileAudit的浏览选项
FileAudit允许用户从审计访问事件中排除掉某些特定事件,用户可以把对于自身来说不敏感的文件审计访问事件设定在这些派出范围之类,这样一来就FileAudit就会自动过滤掉这些不明感时间,以便节约用 ...
- uvm_void 寂静的空宇
空也是一种存在. ——<三体> 文件: $UVM_HOME/src/base/uvm_misc.svh virtual class uvm_void; endclass 在静寂 ...
- JS 字符串 时间 数字函数操作 事件
字符串 操作 var s="abcdefg" s.tolowerCase() 转小写 s.toupperCase() 转大写 s.substring(2,5) 索引下 ...
- watchguard 软件工程师内部招聘!
作为watchguard正式员工,现发布公司最近的招聘信息,待遇优厚,请符合条件的朋友和我联系并将简历发给我,我会尽早联系公司人力部门. 我的邮件:daibao91888@163.com 博客:htt ...
- jquery 不支持$.browser
if (!$.browser) { $.browser = { mozilla : /firefox/.test(navigator.userAgent.toLowerCase()), webkit ...
- UISearchBar clearButton
When the searchBar:textDidChange: method of the UISearchBarDelegate gets called because of the user ...
- softmax_loss的归一化问题
cnn网络中,网络更新一次参数是根据loss反向传播来,这个loss是一个batch_size的图像前向传播得到的loss和除以batch_size大小得到的平均loss. softmax_loss前 ...
- redux是全局状态(数据)的管理机制,局部数据没有意义
redux是全局状态(数据)的管理机制,局部数据没有意义
- C01 C语言基础
目录 C语言简史及特点 C语言开发环境 C语言程序结构 C语言基本输入输出函数 编译 软件类型 C语言简要及特点 什么是计算机语言 计算机语言是用于人与计算机之间通讯的语言. 计算机遵照接收到的计算机 ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061) : 第一次设置MySQL也适用
[MySQL的安装环境]:windows7 64位 [MySQL的版本]:mysql-8.0.16-winx64 [错误描述]: ERROR 2003 (HY000): Can't connect t ...