3412: [Usaco2009 Dec]Music Notes乐谱

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 35  Solved: 30
[Submit][Status]

Description

 

Input

第1行:两个整数N,Q.

第2到N+1行:第i+l行只有一个整数Bi.

第N+2到N+Q+I行:第N+i+l行只有一个整数Ti.

Output

第1到Q行:对与每个询问,在词问的时间内,奶牛敲击的是哪个音阶?

Sample Input

3 5
2
1
3
2
3
4
0
1

Sample Output

2
3
3
1
1

HINT

 

Source

Silver

题解:

二分这个值即可。我们是c++,可以直接lower_bound

400T水了这么一道T_T

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 50000+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,x,a[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();a[]=-;
for1(i,n)x=read(),a[i]=a[i-]+x;
while(m--)printf("%d\n",lower_bound(a+,a+n+,read())-a);
return ;
}

BZOJ3412: [Usaco2009 Dec]Music Notes乐谱的更多相关文章

  1. BZOJ 3412: [Usaco2009 Dec]Music Notes乐谱(离线处理)

    这道题貌似怎么写都可以吧= =,我先读入询问然后从小到大处理就行了= = PS:水水题真的好!无!聊!但是好!欢!乐! CODE: #include<cstdio>#include< ...

  2. 【BZOJ】3412: [Usaco2009 Dec]Music Notes乐谱(二分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3412 维护前缀和,然后直接二分即可... #include <cstdio> #incl ...

  3. BZOJ——3412: [Usaco2009 Dec]Music Notes乐谱

    http://www.lydsy.com/JudgeOnline/problem.php?id=3412 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit:  ...

  4. BZOJ3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者

    3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 47  Solve ...

  5. 1774: [Usaco2009 Dec]Toll 过路费

    1774: [Usaco2009 Dec]Toll 过路费 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 263  Solved: 154[Submit ...

  6. 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者

    3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solve ...

  7. BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd

    BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd 题意: 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一 ...

  8. [bzoj1775][Usaco2009 Dec]Vidgame 电视游戏问题_背包dp

    1775: [Usaco2009 Dec]Vidgame 电视游戏问题 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1775 题解: 发 ...

  9. Floyd | | jzoj[1218] | | [Usaco2009 Dec]Toll 过路费 | | BZOJ 1774 | | 我也不知道该怎么写

    写在前面:老师说这一道题是神题,事实上确实如此,主要是考察对Floyd的理解 ******************************题目.txt************************* ...

随机推荐

  1. mysql数据库sql常用命令

    1.查看索引:mysql> show index from tblname; 2.利用索引查询:SELECT * FROM product WHERE ID > =(select id f ...

  2. Jenkins+maven+git+sonar 系统持续集成&amp;代码单測管理

    Jenkins+maven+git+sonar 系统持续集成&代码单測管理 Jenkins的安装 Jenkins是基于Java开发的一种持续集成工具,用于监控持续反复的工作.功能包含: 1.持 ...

  3. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

  4. 各个函数消耗的时间profiling和内存泄漏valgrind

    来源:http://06110120wxc.blog.163.com/blog/static/37788161201333112445844/ ARM(hisi)上面的profiling和valgri ...

  5. android 接听和挂断实现方式

    参考:android 来电接听和挂断 支持目前所有版本 注意:android2.3版本及以上不支持下面的自动接听方法. (会抛异常:java.lang.SecurityException: Neith ...

  6. LINQ Enumerable

    System.Linq.Enumerable类,提供了数十种称为扩展方法的共享方法,帮助您操作所有实现IEnumerable(of T)接口的类中的数据.由于Enumerable类的扩展方法可以处理许 ...

  7. css样式之边框和内外边距

    1.css样式之边框:border 实心的边框: <!DOCTYPE html><html> <head> <meta http-equiv="co ...

  8. apache的域名添加虚拟端口号

    1. vi /etc/httpd/conf/httpd.conf 2. 搜索Listen 80,在后面添加Listen 8080 3. 重启apache服务器./usr/sbin/apachectl ...

  9. .NET中删除空白字符串的10大方法

    介绍 我们有无数方法可用于删除字符串中的所有空白.大部分都能够在绝大多数的用例中很好工作,但在某些对时间敏感的应用程序中,是否采用最快的方法可能就会造成天壤之别. 如果你问空白是什么,那说起来还真是有 ...

  10. HTML中属性ID和属性NAME的区别(转)

    ID和Name都可以用来标识一个标记,Javascript分别有两个方法getElementById和getElementByName来定位Dom节点. 区别如下: 1.我们知道在网页做Post提交时 ...