• Codeforces Round #143 (Div. 2) (ABCD 思维场)


    题目连链接:http://codeforces.com/contest/231


    A. Team
    time limit per test:2 seconds
    memory limit per test:256 megabytes

    One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

    This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

    Input

    The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Thenn lines contain three integers each, each integer is either0 or1. If the first number in the line equals1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

    Output

    Print a single integer — the number of problems the friends will implement on the contest.

    Sample test(s)
    Input
    3
    1 1 0
    1 1 1
    1 0 0
    
    Output
    2
    
    Input
    2
    1 0 0
    0 1 1
    
    Output
    1
    
    Note

    In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.

    In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.


    懒得说


    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int a[1005][10];
    
    int main()
    {
        int n, ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
        {
            int cnt = 0;
            for(int j = 0; j < 3; j++)
            {
                scanf("%d", &a[i][j]);
                if(a[i][j])
                    cnt ++;
            }
            if(cnt >= 2)
                ans ++;
        }
        printf("%d
    ", ans);
    }


    B. Magic, Wizardry and Wonders
    time limit per test:2 seconds
    memory limit per test:256 megabytes

    Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.

    This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater thanl. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.

    Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.

    Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater thanl, the numbers on the appearing cards can be anything, no restrictions are imposed on them.

    It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there weren cards, they contained integers from 1 tol, and after all magical actions he was left with a single card containing numberd.

    Help Vasya to recover the initial set of cards with numbers.

    Input

    The single line contains three space-separated integers:n (2 ≤ n ≤ 100) — the initial number of cards on the table,d (|d| ≤ 104) — the number on the card that was left on the table after all the magical actions, andl (1 ≤ l ≤ 100) — the limits for the initial integers.

    Output

    If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containingn integers from 1 tol. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.

    Sample test(s)
    Input
    3 3 2
    
    Output
    2 1 2 
    Input
    5 -4 3
    
    Output
    -1
    
    Input
    5 -4 4
    
    Output
    2 4 1 4 1 

    题目大意:n个数字,要求得到d分。每一个数字最大为l,规则是拿倒数第二个数减去最后一个数得到一个新的数放到最后,以此类推直到仅仅剩一个数。这个数就是最后得分,如今要构造这个初始的数字序列

    题目分析:如果n为5,d=a1- (a2-(a3-(a4-a5)))化简即d=a1-a2+a3-a4+a5。从第一个数開始一加一减,我们能够通过一直移项尽量使这个等式成立

    d1=a1-d =a2-a3+a4-a5   若d大于0,a1取最大即l,若d1小于0,a1取最小值即1 (下面d的取值规则同样)

    d2=a2-d1=a3-a4+a5     

    d3=a3-d2=a4-a5

    d4=a4-d3=a5

    这样就能够啦。最后的a5=d4

    由于a是有范围的,假设最后的a值在范围之外则不可能,由于我们选数的宗旨就是让两边尽可能相等


    #include <cstdio>
    int ans[105];
    
    int main()
    {
        int n, d, l;
        scanf("%d %d %d", &n, &d, &l);
        for(int i = 0; i < n - 1; i ++)
        {
            ans[i] = d > 0 ? l : 1;
            d = ans[i] - d;
        }
        ans[n - 1] = d;
        if(ans[n - 1] > l || ans[n - 1] < 1)
            printf("-1
    ");
        else
        {
            for(int i = 0; i < n - 1; i++)
                printf("%d ", ans[i]);
            printf("%d
    ", ans[n - 1]);
        }
    }
    


    C. To Add or Not to Add
    time limit per test:2 seconds
    memory limit per test:256 megabytes

    A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.

    However, before looking for such number, you are allowed to perform not more thank following operations — choose an arbitrary element from the array and add1 to it. In other words, you are allowed to increase some array element by1 no more thank times (you are allowed to increase the same element of the array multiple times).

    Your task is to find the maximum number of occurrences of some number in the array after performing no more thank allowed operations. If there are several such numbers, your task is to find the minimum one.

    Input

    The first line contains two integers n and k (1 ≤ n ≤ 105;0 ≤ k ≤ 109) — the number of elements in the array and the number of operations you are allowed to perform, correspondingly.

    The third line contains a sequence of n integers a1, a2, ..., an(|ai| ≤ 109) — the initial array. The numbers in the lines are separated by single spaces.

    Output

    In a single line print two numbers — the maximum number of occurrences of some number in the array after at mostk allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces.

    Sample test(s)
    Input
    5 3
    6 3 4 0 2
    
    Output
    3 4
    
    Input
    3 4
    5 5 5
    
    Output
    3 5
    
    Input
    5 3
    3 1 2 2 1
    
    Output
    4 2
    
    Note

    In the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence6, 4, 4, 0, 4, where number4 occurs 3 times.

    In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array5, 5, 5, if we increase each by one, we get6, 6, 6. In both cases the maximum number of occurrences equals3. So we should do nothing, as number 5 is less than number6.

    In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence3, 2, 2, 2, 2, where number2 occurs 4 times.



    题目大意:给n个数a1...an。能够有k次操作。当然也能够不操作。每次操作是对当中一个数加1。同一个数能够多次被加,如今求在k次操作内得到的数字频数最大的最小数和其频数


    题目分析:排序,预处理前缀和,对于每一个数向后枚举,计算在其前面第pos位的数到它这位(记为第i位),使这些数都等于a[i]须要的操作次数为
    a[i] * (pos - i) - (sum[i] - sum[pos]),拿此和k比較,不断后移pos,记录答案,注意pos不能每次都从0開始,也没有这个必要,由于我们已经排过序了并且要求的是最小数,第i-1位不满足则第i位必定不满足,因此pos每次直接后移就可以


    #include <cstdio>
    #include <algorithm>
    #define ll long long
    using namespace std;
    int const MAX = 1e5 + 5;
    ll a[MAX], sum[MAX];
    
    int main()
    {
        int n, k; 
        scanf("%d %d", &n, &k);
        for(int i = 1; i <= n; i++)
            scanf("%I64d", &a[i]);
        sort(a + 1, a + n + 1);
        for(int i = 1; i <= n; i++)
            sum[i] = a[i] + sum[i - 1];
        ll ma = 0, ans;
        int pos = 0;
        for(int i = 1; i <= n; i++)
        {
            while(i > pos && a[i] * (i - pos) - (sum[i] - sum[pos]) > k)
                pos ++;
            if(i - pos > ma)
            {
                ma = i - pos;
                ans = a[i];
            }
        }
        printf("%I64d %I64d
    ", ma, ans);
    }



    D. Magic Box
    time limit per test:2 seconds
    memory limit per test:256 megabytes

    One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point(x1, y1, z1). The six faces of the box contain some numbersa1, a2, ..., a6, exactly one number right in the center of each face.

    The numbers are located on the box like that:

    • number a1 is written on the face that lies on the ZOX plane;
    • a2 is written on the face, parallel to the plane from the previous point;
    • a3 is written on the face that lies on the XOY plane;
    • a4 is written on the face, parallel to the plane from the previous point;
    • a5 is written on the face that lies on the YOZ plane;
    • a6 is written on the face, parallel to the plane from the previous point.

    At the moment Vasya is looking at the box from point(x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly theai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees someai = 6, then he can't mistake this number for9 and so on).

    Input

    The fist input line contains three space-separated integersx,y andz (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integersx1,y1, z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.

    It is guaranteed that point (x, y, z) is located strictly outside the box.

    Output

    Print a single integer — the sum of all numbers on the box faces that Vasya sees.

    Sample test(s)
    Input
    2 2 2
    1 1 1
    1 2 3 4 5 6
    
    Output
    12
    
    Input
    0 0 10
    3 2 3
    1 2 3 4 5 6
    
    Output
    4
    
    Note

    The first sample corresponds to perspective, depicted on the picture. Vasya sees numbersa2 (on the top face that is the darkest),a6 (on the right face that is the lightest) anda4 (on the left visible face).

    In the second sample Vasya can only see number a4.


    这样的A题水平的题放在D题位置,纯属恐吓人,也懒得说了


    #include <cstdio>
    int a[7];
    
    int main()
    {
        int x, y, z, x1, y1, z1;
        scanf("%d %d %d %d %d %d", &x, &y, &z, &x1, &y1, &z1);
        for(int i = 1; i <= 6; i++)
            scanf("%d", &a[i]);
        int ans = 0;
        if(y < 0)
            ans += a[1];
        if(y - y1 > 0)
            ans += a[2];
        if(z < 0)
            ans += a[3];
        if(z - z1 > 0)
            ans += a[4];
        if(x < 0)
            ans += a[5];
        if(x - x1 > 0)
            ans += a[6];
        printf("%d
    ", ans);
    }


  • 相关阅读:
    网络负载均衡LVS
    JS 模仿红绿灯(控制台)
    【转】wrk 压力测试的 lua脚本
    linux开机 自动挂载和启动jar包
    【转】jprofiler linux配置需要监听的程序的端口
    时间复杂度总结
    Windows Subsystem for Linux (WSL) 安装
    敬畏用户
    Golang语言HTTP客户端实践
    Groovy入门常用语法
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5322770.html
Copyright © 2020-2023  润新知