2596: Music Notes 

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
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 







1

Sample Output





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的更多相关文章

  1. 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 ...

  2. Android Weekly Notes Issue #237

    Android Weekly Issue #237 December 25th, 2016 Android Weekly Issue #237 这是本年的最后一篇issue, 感谢大家. 本期内容包括 ...

  3. Android Weekly Notes Issue #230

    Android Weekly Notes Issue #230 November 6th, 2016 Android Weekly Issue #230. Android Weekly笔记, 本期内容 ...

  4. Android Weekly Notes Issue #229

    Android Weekly Issue #229 October 30th, 2016 Android Weekly Issue #229 Android Weekly笔记, 本期内容包括: 性能库 ...

  5. Android Weekly Notes Issue #227

    Android Weekly Issue #227 October 16th, 2016 Android Weekly Issue #227. 本期内容包括: Google的Mobile Vision ...

  6. Android Weekly Notes Issue #221

    Android Weekly Issue #221 September 4th, 2016 Android Weekly Issue #221 ARTICLES & TUTORIALS And ...

  7. Android Weekly Notes Issue #219

    Android Weekly Issue #219 August 21st, 2016 Android Weekly Issue #219 ARTICLES & TUTORIALS Andro ...

  8. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  9. MAGIC XPA最新版本Magic xpa 2.4c Release Notes

    New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...

随机推荐

  1. P1809 过河问题_NOI导刊2011提高(01)

    题目描述 有一个大晴天,Oliver与同学们一共N人出游,他们走到一条河的东岸边,想要过河到西岸.而东岸边有一条小船. 船太小了,一次只能乘坐两人.每个人都有一个渡河时间T,船划到对岸的时间等于船上渡 ...

  2. uvm_factory——我们的工厂(二)

    上节我们说到uvm_object_registry #(T),uvm_object_reistry 又继承自uvm_object_wrapper,所以首先,让我们先看看它爹是啥样子的: //----- ...

  3. 对InitialContext的理解

        类InitialContext java.lang.Object   javax.naming.InitialContext 此类是执行命名操作的初始上下文. 所有命名操作都相对于某一上下文. ...

  4. codevs 4165 ​高精度求阶乘

    时间限制: 1 s  空间限制: 256000 KB  题目等级 : 白银 Silver 题目描述 Description 用高精度计算出S=n! 其中"!"表示阶乘,例如:5!= ...

  5. UVA 753 A Plug for UNIX (最大流)

    关键在建图,转换器连一条容量无限的边表示可以转化无数次,设备的插头连源点,插座连汇点. dinic手敲已熟练,输出格式又被坑,总结一下,输出空行多case的,一个换行是必要的,最后一个不加空行,有Te ...

  6. 适用于iOS7 UI的外描边图标素材下载

    我们知道ios7的界面设计是非常简约的,图标也不例外,iOS7的icon大部使用了扁平化的外描边风格设计,使得整体看起来十分简约.耐看,这次分享达人为大家收集将近600个漂亮的外描边图标下载,这些图标 ...

  7. Django ORM 一对一,一对多,多对多, 添加,批量插入和查询

    模型类 class Book(models.Model): nid = models.AutoField(primary_key=True) title = models.CharField(max_ ...

  8. shell脚本自动部署及监控

    一.shell脚本部署nginx反向代理和三个web服务 1 对反向代理服务器进行配置 #!/bin/bash #修改用户交互页面 用户输入参数执行相应的参数 #安装epel扩展包和nginx fun ...

  9. Java截取视频文件缩略图

    /** * 截取视频第0帧的图片 */public static void videoImage(String filePath, String fileName,int widthdist, int ...

  10. House of Spirit(fastbin)

    0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...