• Codeforces Round #427 (Div. 2)


    B. The number on the board
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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的关系,问你要改几位,改成9就好了啊

    #include <bits/stdc++.h>
    using namespace std;
    char s[100005];
    int main() {
        int k;
        scanf("%d",&k);
        scanf("%s",s);
        sort(s,s+strlen(s));
        int i=0,sum=0;
        for(int i=0;s[i];i++)
            sum+=s[i]-'0';
        while(sum<k){
            sum+='9'-s[i++];
        }
        cout<<i;
        return 0;
    }
    A. Key races
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of scharacters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds 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 sv1, 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 14milliseconds. So, the first wins.

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

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

    水题+1

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main() {
        ll s,v1,v2,t1,t2;
        cin>>s>>v1>>v2>>t1>>t2;
        ll q1=2*t1+s*v1;
        ll q2=2*t2+s*v2;
        if(q1<q2)
            cout<<"First";
        else if(q1>q2)
            cout<<"Second";
        else
            cout<<"Friendship";
        return 0;
    }
    C. Star sky
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

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

    Over time the stars twinkle. At moment 0 the i-th star has brightness si. 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 ti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1iy1i) and the upper right — (x2iy2i). 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 nqc (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 xiyisi (1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ 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 tix1iy1ix2iy2i (0 ≤ ti ≤ 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.

     暴力前缀和的,就是这个星星是会重复的

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long  ll;
    const int N=105;
    int a[N][N][12];
    int main() {
        int n,q,c;
        scanf("%d%d%d",&n,&q,&c);
        memset(a,0,sizeof(a));
        int x,y,xx,yy,t,k;
        for(int i=0; i<n; i++) {
            scanf("%d%d%d",&x,&y,&k);
            a[x][y][k]++;
        }
        for(int i=1; i<=100; i++)
            for(int j=1; j<=100; j++)
                for(int k=0; k<=c; k++) {
                    a[i][j][k]+=(a[i-1][j][k]+a[i][j-1][k]-a[i-1][j-1][k]);
                }
        for(int i=0; i<q; i++) {
            scanf("%d%d%d%d%d",&t,&x,&y,&xx,&yy);
            int ans=0;
            for(int i=0; i<=c; i++) {
                int val=(t+i)%(c+1);
                ans+=val*(a[xx][yy][i]+a[x-1][y-1][i]-a[x-1][yy][i]-a[xx][y-1][i]);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    D. Palindromic characteristics
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.

    A string is 1-palindrome if and only if it reads the same backward as forward.

    A string is k-palindrome (k > 1) if and only if:

    1. Its left half equals to its right half.
    2. Its left and right halfs are non-empty (k - 1)-palindromes.

    The left half of string t is its prefix of length ⌊|t| / 2⌋, and right half — the suffix of the same length. ⌊|t| / 2⌋ denotes the length of string tdivided by 2, rounded down.

    Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.

    Input

    The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.

    Output

    Print |s| integers — palindromic characteristics of string s.

    Examples
    input
    abba
    output
    6 1 0 0 
    input
    abacaba
    output
    12 4 1 0 0 0 0 
    Note

    In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.

    k是,那么k-1也是,预处理(好复杂的预处理)

    #include<bits/stdc++.h>
    using namespace std;
    const int N=5005;
    string str;
    int dp[N][N];
    bool p[N][N];
    bool seen[N][N];
    int c[N];
    int n;
    bool palindrome(int l,int r) {
        if(l==r) return p[l][r]=1;
        if(l+1==r)return p[l][r]=(str[l]==str[r]);
        if(seen[l][r]) return p[l][r];
        seen[l][r]=1;
        if(str[l]==str[r]) return p[l][r]=palindrome(l+1,r-1);
        return p[l][r]=0;
    }
    int solve(int l,int r) {
        if(l==r) return dp[l][r]=1;
        if(dp[l][r]!=-1)return dp[l][r];
        if(palindrome(l,r)) {
            int m=(l+r)/2;
            return dp[l][r]=1+solve(m+1,r);
        }
        return dp[l][r]=0;
    }
    int main() {
        ios::sync_with_stdio(0);
        cin>>str;
        n=(int)str.size();
        memset(dp,-1,sizeof(dp));
        for(int i=0; i<n; i++)
            for(int j=i; j<n; j++)
                c[solve(i,j)]++;
        for(int i=n-1; i>=1; i--)
            c[i]+=c[i+1];
        for(int i=1; i<n; i++)
            cout<<c[i]<<" ";
        cout<<c[n]<<endl;
        return 0;
    }
    大佬您太强了,还请多多指教哎
  • 相关阅读:
    IntelliLock
    XAF How to show custom forms and controls in XAF (Example)
    [转] How to Show Usual Winform as View in XAF
    Strong name signature not valid for this assembly Microsoft.mshtml.dll
    各廠商ERP系統架構圖連結 (ERP流程圖)(轉)
    [原] XAF How can I change XafDisplayNameAttribute dynamically
    [原] XAF How to implement a custom attribute to customize the Application Model
    [转] XAF 存储多币种代码列表的三种方法
    [原] XAF 如何将数据库中Byte array图片显示出来
    [原] XAF 如何基于业务规则禁用属性
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7266951.html
Copyright © 2020-2023  润新知