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 ...
随机推荐
- SQL server事务语法
ALTER proc [dbo].[p_BOGetMCBSecurityCheckPropertiesTypeAdd]@Name nvarchar(50), ---参数@MCBBadlyBuil ...
- SQL Server插入中文数据出现乱码问题
我在用sql server存储数据的时候发现中文全变成了问号,我知道中文是特殊的编码.所以在数据库设计的时候包含中文的字段就是nvarchar,但是还是成了问号 好了,不多说了,解决方案如下: 在存储 ...
- 阻止除root外的其他用户登录
在对系统进行某些更新时,你可能不希望用户登录,这时可以使用/ e t c / n o l o g i n文件,大多数系统都提供这个文件.一旦在/ e t c目录中使用t o u c h命令创建了一个名 ...
- 查询sqlserver数据库,表占用数据大小
if exists(select 1 from tempdb..sysobjects where id=object_id('tempdb..#tabName') and xtype='u')dro ...
- shiro : java.lang.IllegalArgumentException: Odd number of characters.
shiro使用的时候: java.lang.IllegalArgumentException: Odd number of characters. at org.apache.shiro.cod ...
- Android(java)学习笔记145:Handler消息机制的原理和实现
联合学习 Android 异步消息处理机制 让你深入理解 Looper.Handler.Message三者关系 1. 首先我们通过一个实例案例来引出一个异常: (1)布局文件activity_m ...
- 多源最短路径 – Floyd-Warshall Algorithm
介绍: 是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权(但不可存在负权回路)的最短路径问题,同时也被用于计算有向图的传递闭包. Floyd-Warshall算法的时间复杂度是O(N3) ...
- atom 自定义快捷键
'atom-text-editor': 'shift-alt-i':'core:move-up' 'shift-alt-space':'core:move-down' 'shift-alt-l':'c ...
- CentOS 7.0关闭防火墙
.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止fir ...
- Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'userController' method
在使用SpringMVC的时候遇到了这个问题 问题原因: 在指定方法所对应的url地址的时候重复了, 也就是@RequestMapping("url")中, 两个方法使用了同一个 ...