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 ...
随机推荐
- tar打包压缩命令
1. tar命令 用法: tar [选项...] [FILE]... GNU ‘tar’将许多文件一起保存至一个单独的磁带或磁盘归档,并能从归档中单独还原所需文件. 示例 tar -cf archiv ...
- Vue.js中data,props和computed数据
data data 是Vue实例的数据对象.Vue将会将data 的属性转换为 getter/setter, 也就是用Object.defineProperty方法(在官网里面有深入响应式原理里面具体 ...
- Objective-C language
Objective-C is the primary language used to write Mac software. If you're comfortable with basic obj ...
- [windows]设置使用空白密码进行远程登录
前提:系统用户设置了空白密码 方法1步骤: 开始菜单--〉运行--〉输入:gpedit.msc--> 计算机配置--〉Windows设置--〉安全设置--〉本地策略--〉安全选项:帐户:使用空白 ...
- QT如何设置应用程序的图标
QT如何设置应用程序的图标 准备:.ico格式的图片,可以选择任意其他图片格式的一张图片用格式工厂转换成.ico图片 例如选用的图片是Application.ico 把图片放到工程目录下 在工 ...
- POJ 2955 Brackets (区间DP,常规)
题意: 给出一个字符串,其中仅仅含 “ ( ) [ ] ” 这4钟符号,问最长的合法符号序列有多长?(必须合法的配对,不能混搭) 思路: 区间DP的常规问题吧,还是枚举区间[i->j]再枚举其中 ...
- 9.18 New Start
好久没上cnblogs,今天提示我说园龄已经2年1个月了.今天就用一个日记的形式开始第一篇博客吧.我以后比较精髓的文章就放在cnblogs,csdn博客也继续会更新,不过也会慢慢提高文章质量. 今天是 ...
- python 基础网络编程2
python 基础网络编程2 前一篇讲了socketserver.py中BaseServer类, 下面介绍下TCPServer和UDPServer class TCPServer(BaseServer ...
- UVa 12219 Common Subexpression Elimination (stl,模拟,实现)
一般来说,把一颗子树离散成一个int,把一个结点的字符离散成一个int会方便处理 直接map离散.当然一个结点最多只有4个小写字母,也可以直接编码成一个27进制的整数,舍掉0,为了区分0和0000. ...
- Java IO file文件的写入和读取及下载
一.FileWriter 和BufferedWriter 结合写入文件 FileWriter是字符流写入字符到文件.默认情况下,它会使用新的内容代替文件原有的所有内容,但是,当指定一个true值作为F ...