• CF round280


    最水的一场CF..

    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.

    Sample test(s)
    input
    1
    output
    1
    input
    25
    output
    4

    没什么好说的,直接乱搞
    /********************
    1+2+...+x <= n, 得到最大的x
    CF 492A Vanya and Cubes
    **********************/#include<bits/stdc++.h>
    using namespace std;
    
    int main(){
        int n, i, ans = 0, sum = 0, temp = 0;
        cin>>n;
        for(i = 1; i <= n; i ++){
           temp += i;
            sum += temp;
            if(sum > n)break;
            ans ++;
        }
        cout<<ans<<endl;
    }
    View Code
    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 ≤ 1000, 1 ≤ 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.

    Sample test(s)
    input
    7 15
    15 5 3 7 9 14 0
    output
    2.5000000000
    input
    2 5
    2 5
    output
    2.0000000000

    注意边界处理
    /********************
    1 ≤ l ≤ 10^9的路上,给出一堆一维的点 1000个之内,为路灯。所有路灯的照明范围相同,问能照明整条路的最小范围是多少
    相邻两个点距离最大值/2,0-第一个路灯 最后一个路灯-l
    取最大值
    第一反应居然还二分了一下真是被自己蠢死= =
    CF 492A Vanya and Cubes
    **********************/
    #include <bits/stdc++.h>
    using namespace std;
    #define N 1004
    int a[N];
    int main(){
        int n, l, i, ans = 0;
        cin>>n>>l;
        for(i = 1; i <= n; i++)cin>>a[i];
        a[0] = 0;
        sort(a, a +n +1);
        for(i = 1; i <= n; i++){
            ans = max(ans, a[i] - a[i-1]);
        }
        //printf("%d
    ", a[1]);
        ans = max(a[1] *2, ans);   ans = max((l-a[n])*2, ans);
        printf("%.10f
    ", ans *1.0 / 2.0);
    }
    View Code
    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 ≤ 105, 1 ≤ r ≤ 109, 1 ≤ 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.

    Sample test(s)
    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

    /********************
    10^5门课,每门课最多得到r分,r<=10^9,需要平均分为avg,avg <= min(10^6,r)
    已知第i门课已经得到ai分,1 ≤ ai ≤ r,每写bi篇论文可以多得一分,1 ≤ bi ≤ 10^6
    问最少需要些多少篇论文可以获得平均分
    
    按b的值统计,即写b篇论文可以拿一分的课还能拿几分
    按b 从小到大,直至凑满分数
    492C. Vanya and Exams
    **********************/
    #include <bits/stdc++.h>
    using namespace std;
    
    #define N 1000005
    #define LL __int64
    LL lt[N];
    int n, r, avg;
    long long sum = 0, nowget = 0, ans = 0;
    
    void input(){
        int a,  b;
        cin >> n >> r >> avg;
        sum = (LL) n * avg;
    
        memset(lt, 0, sizeof(lt));
        for(int i = 1; i <= n; i++){
            cin>>a>>b;
            lt[b] += (r - a);
            nowget += a;
        }
    }
    
    void gao(void){
        sum -= nowget;
        for(int i = 1; i <= N; i++){
            if(sum > 0){
                ans += min(sum, lt[i]) * i;
                sum -= min(sum, lt[i]);
            }
            else break;
        }cout<<ans<<endl;
    }
    int main(void){
        input();
        gao();
    }
    View Code
    D. Vanya and Computer Game
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits.

    Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.

    Input

    The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.

    Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.

    Output

    Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.

    Sample test(s)
    input
    4 3 2
    1
    2
    3
    4
    output
    Vanya
    Vova
    Vanya
    Both
    input
    2 1 1
    1
    2
    output
    Both
    Both
     一开始以为是要从1开始依次打这些怪物,是连续关系。。
    还看成了A打一下可以掉x点,B打一下掉y点,感觉有些麻烦。
    后来发现自己想多了。
     
    打了个表,打怪以lca(x, y)为周期。周期内打个表出来。
    表的大小不会超过两倍的max(x,y)
    接下来取模就可以了
    /********************
     一开始以为是要从1开始依次打这些怪物,是连续关系。。
    还看成了A打一下可以掉x点,B打一下掉y点,感觉有些麻烦。
    后来发现自己想多了。
    
    打了个表,打怪以lca(x, y)为周期。周期内打个表出来。
    表的大小不会超过两倍的max(x,y)
    接下来取模就可以了
    
    解释一下表。a每个1/x分钟打 一下可以看做每隔y分钟打一下,同样的变换b
    按从小到大的打击顺序打个表
    注意爆longlong re了 = =
    D. Vanya and Computer Game
    **********************/
    #include<bits/stdc++.h>
    using namespace std;
    #define LL __int64
    #define N 10000007
    int typ[N];
    string st[3] = {"Vanya","Vova", "Both"};
    int main(void){
        int i, n,  z, j, tot =0;
        LL x, y;
        cin>>n>>x>>y;
    
        LL m = __gcd(x,y);
        m = x / m * y;
        i = j = 1;
        //0->xy
        typ[0] = 2;
       // cout<<m<<endl;
        while(i * y <= m && j * x <= m){
            if(i * y < j * x){
                typ[++tot] = 0;
                i++;
            }
            else if(j * x < i * y){
                typ[++tot] = 1;
                j++;
            }
            else{
                typ[++tot] = 2;
                break;
            }
            //printf("%d %d %d
    ", tot, i, j);
        }
    //cout<<tot<<endl;
        tot++;
        while(n--){
            cin>>x;
            cout<<st[typ[x%tot]]<<endl;
    
        }
    }
    View Code
    E. Vanya and Field
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates(xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell . The following condition is satisfied for the vector: , where  is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.

    Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

    Input

    The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 ≤ xi, yi ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

    Output

    Print two space-separated numbers — the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.

    Sample test(s)
    input
    5 5 2 3
    0 0
    1 2
    1 3
    2 4
    3 1
    output
    1 3
    input
    2 3 1 1
    0 0
    0 1
    1 1
    output
    0 0

    /********************
    n*n的方格,m个点上有苹果。每次从现在的点(x, y)走到((x+dx)%n, (y+dy)%m)
    n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) 
    ndx互质,ndy互质
    走到之前走过的点则停止。
    问任选一个点开始走最多能搞到多少苹果。
    
    一开始还想图论啥的想多了= =
    注意到一堆互质,所以n是底之类的东西,也就是k*(dx) % n 当k从0~n-1可以取遍0~n-1所有值。
    所以走n步之后一定回到本点,每个点都对应的可以走到(i,0),独一无二的映射。而且有(i+k*(dx))%n 显然与(0+k*(dx))%n的某种差是一个定值
    因此先处理出0,0到达的点,即f[x]为到第i行的时候的列数。
    这样取出最多的路径就方便了 
    **********************/
    #include<bits/stdc++.h>
    using namespace std;
    #define N 1000004
    int f[N], cnt[N]; 
    
    void gao(void){
        int n, m, dx, dy;
        scanf("%d%d%d%d", &n, &m, &dx, &dy);
        int x, y, t, ans = -1, loc;
        x = y = 0;
        for(int i = 0; i < n; i++){
            f[x] = y;
            x  = (x +dx) % n;
            y = (y + dy) % n;
        }
        while(m--){
            scanf("%d%d", &x, &y);
            t = (y - f[x] + n) % n;
            cnt[t]++;
            if(cnt[t] > ans){
                ans = cnt[t];
                loc = t;
            }
        }
        printf("%d %d
    ", 0, loc);
    }
    int main(void){
    
        gao();
    }
    View Code
  • 相关阅读:
    【UVA–11997 K Smallest Sums 】
    【LA 3027 Corporative Network】
    【bzoj3173-最长上升子序列-一题两解】
    【Rain in ACStar HDU-3340】
    【Uva 11280 飞到弗雷德里顿】
    【Uva 10269 马里奥与公主的归途】
    【Uva 11604 编码都有歧义了】
    【RevolC FaeLoN Uva 10972】
    oracle解析xml(增加对9i版本的支持)
    acl操作记录
  • 原文地址:https://www.cnblogs.com/bbbbbq/p/4170763.html
Copyright © 2020-2023  润新知