zoukankan      html  css  js  c++  java
  • Codeforces Round #427 (Div. 2)

    Codeforces Round #427 (Div. 2)

    A. Key races

    Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2milliseconds and has ping t2 milliseconds.

    If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:

    1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.

    2. Right after that he starts to type it.

    3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.

    The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.

    Given the length of the text and the information about participants, determine the result of the game.

    Input

    The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.

    Output

    If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".

    Examples

    input

    5 1 2 1 2

    output

    First

    input

    3 3 1 1 1

    output

    Second

    input

    4 5 3 1 5

    output

    Friendship

    Note

    In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.

    In the second example, information on the success of the first participant comes in 11milliseconds, of the second participant — in 5 milliseconds. So, the second wins.

    In the third example, information on the success of the first participant comes in 22milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.

    题意:

    题目很长,但是案例很好看,就是说,打字的速度和电脑的延迟,打S个字母,看谁先打完。

    #include <bits/stdc++.h>
    ​
    using namespace std;
    ​
    int main()
    {
        int s,v1,v2,t1,t2;
        scanf("%d%d%d%d%d",&s,&v1,&v2,&t1,&t2);
    ​
        int f = s*v1+2*t1;
        int se = s*v2+2*t2;
        if(f<se)
            puts("First");
        else if(f>se)
            puts("Second");
        else puts("Friendship");
    ​
        return 0;
    }

    B. The number on the board

    Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.

    You have to find the minimum number of digits in which these two numbers can differ.

    Input

    The first line contains integer k (1 ≤ k ≤ 109).

    The second line contains integer n (1 ≤ n < 10100000).

    There are no leading zeros in n. It's guaranteed that this situation is possible.

    Output

    Print the minimum number of digits in which the initial number and n can differ.

    Examples

    input

    3
    11

    output

    1

    input

    3
    99

    output

    0

    Note

    In the first example, the initial number could be 12.

    In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

    题意:有一个数字原来的各位数字之和>=k,现在变成了n,求最少改变了多少位。

    分析:看上去很复杂,梳理好思路。各位数字之和>=k ,那么这个数是OK的,不需变化,否则,求出每一位最多还能变多少,排序,前缀和,套路。

    #include <bits/stdc++.h>
    ​
    using namespace std;
    ​
    char str[100005];
    ​
    bool cmp(int a,int b) {
        return a > b;
    }
    ​
    int main()
    {
        int k;
        scanf("%d",&k);
        scanf("%s",str);
    ​
        int len = strlen(str);
        int sum = 0;
    ​
        int a[100005];
        for(int i=0; i < len; i++) {
            sum += str[i] - '0';
            a[i] = 9 - (str[i] - '0');
        }
    ​
        sort(a,a+len,cmp);
    ​
        for(int i=1;i<len;i++)
            a[i] = a[i-1] + a[i];
    ​
        if(sum>=k)
            puts("0");
        else {
            int ans = k - sum;
            for(int i=0;i<len;i++) {
                if(a[i]>=ans) {
                    printf("%d
    ",i+1);
                    break;
                }
            }
    ​
        }
    ​
        return 0;
    }

    C. Star sky

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (x**i, y**i), a maximum brightness c, equal for all stars, and an initial brightness s**i(0 ≤ s**i ≤ c).

    Over time the stars twinkle. At moment 0 the i-th star has brightness s**i. Let at moment t some star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and 0, otherwise.

    You want to look at the sky q times. In the i-th time you will look at the moment t**i and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1i, y1i) and the upper right — (x2i, y2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.

    A star lies in a rectangle if it lies on its border or lies strictly inside it.

    Input

    The first line contains three integers n, q, c (1 ≤ n, q ≤ 105, 1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.

    The next n lines contain the stars description. The i-th from these lines contains three integers x**i, y**i, s**i (1 ≤ x**i, y**i ≤ 100, 0 ≤ s**i ≤ c ≤ 10) — the coordinates of i-th star and its initial brightness.

    The next q lines contain the views description. The i-th from these lines contains five integers t**i, x1i, y1i, x2i, y2i (0 ≤ t**i ≤ 109, 1 ≤ x1i < x2i ≤ 100, 1 ≤ y1i < y2i ≤ 100) — the moment of the i-th view and the coordinates of the viewed rectangle.

    Output

    For each view print the total brightness of the viewed stars.

    Examples

    input

    2 3 3
    1 1 1
    3 2 0
    2 1 1 2 2
    0 2 1 4 5
    5 1 1 5 5

    output

    3
    0
    3

    input

    3 4 5
    1 1 2
    2 3 0
    3 3 1
    0 1 1 100 100
    1 2 2 4 4
    2 2 1 4 7
    1 50 50 51 51

    output

    3
    3
    5
    0

    Note

    Let's consider the first example.

    At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.

    At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.

    At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.

    题意:

    感觉这一次的题意都超长的,意思是:有n个坐标,上面是一个星星,有一个初始亮度s,随着时间变化,亮度为[0,c] 之间,也就是说%(c+1),然后,t 秒时刻,就是 (t+s)%(c+1);

    对于每个区间,找到有哪些点——(二分) ,麻烦了点。然后一个前缀和,注意s秒是多个。

    麻烦了点,有更好的方案:

    前缀和,三维:时间,x ,y,那么,这里就有一个类似于容斥定理。初始化,和询问同样。

    #include <bits/stdc++.h>
    ​
    using namespace std;
    ​
    const int MAX_N = 1e5+5;
    typedef long long ll;
    typedef pair<int,int> P;
    ​
    #define INF 0x3f3f3f3f
    ​
    int a[12][MAX_N];
    P b[MAX_N];
    int sum[12][110][110];
    int maze[12][110][110];
    ​
    ​
    ​
    int main(int argc, char const *argv[]) {
    ​
        int n,m,k;
        scanf("%d%d%d",&n,&m,&k);
    ​
        for(int i=1; i <= n; i++)
            scanf("%d%d%d",&b[i].first,&b[i].second,&a[0][i]);
    ​
        for(int i=0; i <= k; i++) {
            for(int j=1; j<=n; j++) {
                maze[i][b[j].first][b[j].second] +=(a[0][j]+i)%(k+1);
            }
        }
    ​
        for(int ks=0; ks<=k; ks++) {
            for(int i=1; i <110;i++) {
                for(int j=1; j <110;j++) {
                    sum[ks][i][j] = sum[ks][i][j-1] + sum[ks][i-1][j] - sum[ks][i-1][j-1] + maze[ks][i][j];
                }
            }
        }
    ​
        for(int i=1; i <= m; i++) {
            int t,x1,y1,x2,y2;
            scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
            printf("%d
    ",sum[t%(k+1)][x2][y2]-sum[t%(k+1)][x2][y1-1]-sum[t%(k+1)][x1-1][y2]+sum[t%(k+1)][x1-1][y1-1]);
        }
    ​
        return 0;
    }
  • 相关阅读:
    列表
    break和continue
    第三天下午
    第二天
    简历,面试
    周三&nbsp;景安
    应届生求职优势(我的求职心…

    2013年01月02日
    Click&nbsp;and&nbsp;Drag
  • 原文地址:https://www.cnblogs.com/TreeDream/p/7429114.html
Copyright © 2011-2022 走看看