zoukankan      html  css  js  c++  java
  • Codeforces Round #280 (Div. 2) A , B , C

    A. Vanya and Cubes
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.

    Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

    Input

    The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

    Output

    Print the maximum possible height of the pyramid in the single line.

    Examples
    input
    1
    output
    1
    input
    25
    output
    4
    Note

    Illustration to the second sample:

    题意:能堆几层,一层(1-n)的和;

    思路:水;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
    int a[N];
    int main()
    {
        int x,sum=0;
        for(int i=1;i<=1000;i++)
        {
            sum+=i;
            a[i]=sum+a[i-1];
        }
        scanf("%d",&x);
        printf("%d
    ",upper_bound(a+1,a+1001,x)-(a+1));
        return 0;
    }
    B. Vanya and Lanterns
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.

    Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?

    Input

    The first line contains two integers nl (1 ≤ n ≤ 10001 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.

    The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.

    Output

    Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

    Examples
    input
    7 15
    15 5 3 7 9 14 0
    output
    2.5000000000
    input
    2 5
    2 5
    output
    2.0000000000
    Note

    Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment[3, 5]. Thus, the whole street will be lit.

    题意:n个灯,L长度的路,求灯最少的照射长度,使得灯把这路全部照亮;

    思路:拍个序,前后端点特判;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
    double a[N];
    int main()
    {
        int n,l;
        scanf("%d%d",&n,&l);
        for(int i=1;i<=n;i++)
            scanf("%lf",&a[i]);
        sort(a+1,a+1+n);
        double ans=0;
        for(int i=2;i<=n;i++)
            ans=max(ans,(a[i]-a[i-1])/2);
        ans=max(a[1],max(ans,l-a[n]));
        printf("%f
    ",ans);
        return 0;
    }
    C. Vanya and Exams
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi essays. He can raise the exam grade multiple times.

    What is the minimum number of essays that Vanya needs to write to get scholarship?

    Input

    The first line contains three integers nravg (1 ≤ n ≤ 1051 ≤ r ≤ 1091 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.

    Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r1 ≤ bi ≤ 106).

    Output

    In the first line print the minimum number of essays.

    Examples
    input
    5 5 4
    5 2
    4 7
    3 1
    3 2
    2 5
    output
    4
    input
    2 5 4
    5 2
    5 2
    output
    0
    Note

    In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.

    In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
    struct grade
    {
        ll a,b;
        bool operator <(const grade &a)const
        {
            return b<a.b;
        }
    }a[N];
    int main()
    {
        ll n,r,ave;
        scanf("%lld%lld%lld",&n,&r,&ave);
        ll sum=ave*n,ans=0;
        for(int i=1;i<=n;i++)
            scanf("%lld%lld",&a[i].a,&a[i].b),sum-=a[i].a;
        sort(a+1,a+n+1);
        if(sum<=0)
        return puts("0");
        for(int i=1;i<=n;i++)
            ans+=min(sum,r-a[i].a)*a[i].b,sum-=min(sum,r-a[i].a);
        printf("%lld
    ",ans);
        return 0;
    }
    A. Vanya and Cubes
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.

    Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

    Input

    The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

    Output

    Print the maximum possible height of the pyramid in the single line.

    Examples
    input
    1
    output
    1
    input
    25
    output
    4
    Note

    Illustration to the second sample:

  • 相关阅读:
    编辑语言发展历史
    正则表达式
    css
    伪类和伪元素区别
    WEB 之API端口
    event flow (Dow)
    for衍生对象
    前端语言的发展
    document
    password user message email的正则表达式
  • 原文地址:https://www.cnblogs.com/jhz033/p/5917607.html
Copyright © 2011-2022 走看看