TOJ 2596: Music Notes

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[105],n,q;
int BS(int x)
{
    int l=1,r=n;
    while(l<=r)
    {
        int mi=(l+r)/2;
        if(a[mi]>x)r=mi-1;
        else l=mi+1;
    }
    return l;
}
int main()
{
    while(~scanf("%d%d",&n,&q))
    {
        scanf("%d",&a[1]);
        for(int i=2;i<=n;i++)
        {
            scanf("%d",&a[i]);
            a[i]+=a[i-1];
        }
        while(q--)
        {
            int x;scanf("%d",&x);
            printf("%d\n",BS(x));
        }
    }
    return 0;
}

原题数据范围应该很大,这个暴力复杂度都还正常

#include<stdio.h>
#include<algorithm>
using namespace std;
int a[105],n,q;
int main()
{
    while(~scanf("%d%d",&n,&q))
    {
        scanf("%d",&a[1]);
        for(int i=2;i<=n;i++)
        {
            scanf("%d",&a[i]);
            a[i]+=a[i-1];
        }
        while(q--)
        {
            int x;scanf("%d",&x);
            printf("%d\n",(int)(upper_bound(a+1,a+n+1,x)-a));
        }
    }
    return 0;
}
时间: 11-03

TOJ 2596: Music Notes的相关文章

84. 从视图索引说Notes数据库(下)

作用和代价上文介绍了关系型数据库里的索引.Notes数据库里的索引隐藏在视图概念里(本文的讨论只针对Notes的视图索引,不包含全文索引.).开发人员创建的视图仅仅是存放在数据库里的一条设计文档,数据库引擎会依据它创建和更新索引.关系型数据库里的索引是从记录中抽取的数据排序而组成的数据结构(主要是B树),Notes视图的索引还包括未排序的列.计算值.分类.总计等等数据(数据结构仍然是B树,如果运气足够好的话,你会遇到Notes报出B-tree structure is invalid的错误).用

Codeforces 538C. Tourist&#39;s Notes

A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning that t

Notes of Daily Scrum Meeting(11.5)

Notes of Daily Scrum Meeting(11.5) 今天是我们学习学长代码,同时学习安卓语言的第三天.我们和学长沟通了一下,仔细讨论后得出一个结论,学长在 IOS平台上的代码可以借鉴,但是很多地方是不能移植过去的,需要我们进行重写,最主要的原因还是IOS平台和Android 平台上的差异性,就比如说:在IOS平台上编写UI会非常简单,在Xcode上拉一个界面出来只需要写很简单的代码就能实现 一个很炫的效果,但是在Android平台上,所有的UI效果都需要自己去搭建实现,因此,我

BZOJ1531: [POI2005]Bank notes

1531: [POI2005]Bank notes Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 229  Solved: 119[Submit][Status] Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值k求最少要用多少个硬币. Input 第一行一个数 n, 1 <= n <

[notes] ImageNet Classification with Deep Convolutional Neual Network

Paper: ImageNet Classification with Deep Convolutional Neual Network Achievements: The model addressed by Alex etl. achieved top-1 and top-5 test error rate of 37.5% and 17.0% of classifying the 1.2 million high-resolution images in the ImageNet LSVR

NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung

NOTES :  A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung  背景知识: Gas exchange is the essential function of the lung. In general, a lung can be viewed as a porous medium(多孔介质) consisting of capillary(毛细管) circuits with

Think in C++ notes, Ch2 &amp; 3, Objects &amp; Class

留待修改 私货:啊这个标题逼格好高 5.2 10:36 开始阅读 Think in C++ notes, Ch2 & 3, Objects & Class,布布扣,bubuko.com

Advice for Applying Machine Learning &amp; Machine Learning System Design----- Stanford Machine Learning(by Andrew NG)Course Notes

Adviceforapplyingmachinelearning Deciding what to try next 现在我们已学习了线性回归.逻辑回归.神经网络等机器学习算法,接下来我们要做的是高效地利用这些算法去解决实际问题,尽量不要把时间浪费在没有多大意义的尝试上,Advice for applying machine learning & Machinelearning system design 这两课介绍的就是在设计机器学习系统的时候,我们该怎么做? 假设我们实现了一个正则化的线性回

Priceless Notes

[Priceless Notes] 1.人类对价格的绝对值没有准确的判断,但是价格或物体的相对值有较准确的判断. 2.物理强度与主观体验的关联成幂曲线.如60瓦的灯会让人觉得亮,但要让人觉得2倍亮的话,则需要4倍的亮度.又如某种程序的糖让人觉得甜,但要想2倍甜的话只需要1.7倍的糖就够了.也就是相同的刺激比率可以得出相同的主观比率. 3.心理状态决定着经济决策. 4.100%的事情和99%的事情,在主观上有着巨大的差异.这种差异会表现在价格和选择上.与此同时,10%和11%的概率差异可以忽略不计