• BZOJ3412: [Usaco2009 Dec]Music Notes乐谱


    3412: [Usaco2009 Dec]Music Notes乐谱

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

    Description

     

    Input

        1行:两个整数NQ.

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

        N+2N+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

    代码:

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #include<string>
    12 #define inf 1000000000
    13 #define maxn 50000+100
    14 #define maxm 500+100
    15 #define eps 1e-10
    16 #define ll long long
    17 #define pa pair<int,int>
    18 #define for0(i,n) for(int i=0;i<=(n);i++)
    19 #define for1(i,n) for(int i=1;i<=(n);i++)
    20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    22 #define mod 1000000007
    23 using namespace std;
    24 inline int read()
    25 {
    26     int x=0,f=1;char ch=getchar();
    27     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    28     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    29     return x*f;
    30 }
    31 int n,m,x,a[maxn];
    32 int main()
    33 {
    34     freopen("input.txt","r",stdin);
    35     freopen("output.txt","w",stdout);
    36     n=read();m=read();a[0]=-1;
    37     for1(i,n)x=read(),a[i]=a[i-1]+x;
    38     while(m--)printf("%d
    ",lower_bound(a+1,a+n+1,read())-a);
    39     return 0;
    40 }
    View Code
  • 相关阅读:
    笔试题 易错题目解析
    SqlServer 函数 大全
    视频上传到自己的服务器打不开
    sql 计算生日提请日期
    Web API 异常处理(转)
    微软源代码管理工具TFS2013安装与使用详细图文教程(Vs2013)
    关于枚举的用法和类型转换
    html title换行方法 如a链接标签内title属性鼠标悬停提示内容换行
    JS的parent、opener、self对象
    uploadfiy
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/4006718.html
Copyright © 2020-2023  润新知