zoukankan      html  css  js  c++  java
  • Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)

    这场据说很难,但是做起来感觉还好的

    A. Restaurant Tables
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In a small restaurant there are a tables for one person and b tables for two persons.

    It it known that n groups of people come today, each consisting of one or two people.

    If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.

    If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.

    You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.

    Input

    The first line contains three integers na and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.

    The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.

    Output

    Print the total number of people the restaurant denies service to.

    Examples
    input
    4 1 2
    1 2 1 1
    output
    0
    input
    4 1 1
    1 1 2 1
    output
    2
    Note

    In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.

    In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.

    水题啊,直接上题意

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int ans=0,c=0,n,a,b;
        cin>>n>>a>>b;
        for(int i=0; i<n; i++) {
            int x;
            scanf("%d",&x);
            if(x==1) {
                if(a) a--;
                else if(b) c++,b--;
                else if(c) c--;
                else if(!a&&!b) ans++;
            } else {
                if(b) b--;
                else ans+=2;
            }
        }
        printf("%d
    ",ans);
        return 0;
    }
    B. Black Square
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.

    You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.

    Input

    The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.

    The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.

    Output

    Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.

    Examples
    input
    5 4
    WWWW
    WWWB
    WWWB
    WWBB
    WWWW
    output
    5
    input
    1 2
    BB
    output
    -1
    input
    3 3
    WWW
    WWW
    WWW
    output
    1
    Note

    In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).

    In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.

    In the third example all cells are colored white, so it's sufficient to color any cell black.

    现在你有一盘黑白棋,你需要改变最少的白棋使其变成正方形,所以找黑棋,在上面,在下面,分情况

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
        int n,m,ans=0;
        cin>>n>>m;
        char a;
        int imi=105,jmi=105,ima=0,jma=0;
        for(int i=1; i<=n; i++)
            for(int j=1; j<=m; j++) {
                cin>>a;
                if(a=='B') {
                    ans++;
                    imi=min(imi,i);
                    ima=max(ima,i);
                    jmi=min(jmi,j);
                    jma=max(jma,j);
                }
            }
        int k=max(ima-imi,jma-jmi)+1;
        if(!ans) printf("1
    ");
        else if(n>=k&&m>=k)
            printf("%d
    ",k*k-ans);
        else printf("-1
    ");
        return 0;
    }
    C. String Reconstruction
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.

    Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.

    You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

    Input

    The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers.

    The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings ti doesn't exceed 106, 1 ≤ xi, j ≤ 106, 1 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide.

    It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.

    Output

    Print lexicographically minimal string that fits all the information Ivan remembers.

    Examples
    input
    3
    a 4 1 3 5 7
    ab 2 1 5
    ca 1 4
    output
    abacaba
    input
    1
    a 1 3
    output
    aaa
    input
    3
    ab 1 1
    aba 1 3
    ab 2 3 5
    output
    ababab

     上来我就是一个数据结构,并查集来玩玩,模拟下题目的操作就行了

    #include<stdio.h> 
    using namespace std;  
    const int N=3000005;
    int f[N];  
    char ans[N],a[N];  
    int find(int a)  
    {  
        int r=a;  
        while(f[r]!=r)  
        r=f[r];  
        int i=a;  
        int j;  
        while(i!=r)  
        {  
            j=f[i];  
            f[i]=r;  
            i=j;  
        }  
        return r;  
    }  
    void merge(int a,int b)  
    {  
        int A,B;  
        A=find(a);  
        B=find(b);  
        if(A>B)  
        {  
            f[B]=A;  
        }  
        else f[A]=B;  
    }  
    int main()  
    {  
        int n;  
        while(~scanf("%d",&n))  
        {  
            memset(ans,' ',sizeof(ans));  
            int end=0;  
            for(int i=1;i<=3000000-80;i++)f[i]=i;  
            for(int i=1;i<=n;i++)  
            {  
                scanf("%s",a);  
                int l=strlen(a);  
                int ki;  
                scanf("%d",&ki);  
                while(ki--)  
                {  
                    int x;  
                    scanf("%d",&x);  
                    int t=x;  
                    end=max(end,l+x-1);  
                    while(x<=t+l-1)  
                    {  
                        ans[x]=a[x-t+1-1];  
                        x=find(x);  
                        if(x<=t+l-1)merge(x,x+1);  
                    }  
                }  
            }  
            for(int i=1;i<=end;i++)  
            {  
                if(ans[i]==' ')ans[i]='a';  
                printf("%c",ans[i]);  
            }  
            printf("
    ");  
        }  
    }
  • 相关阅读:
    vtk体绘制时采样的起点使用噪声纹理来进行扰动
    转:轻松搞死VS
    虚拟华师(UDK)
    虚拟手术中的血流模拟(Physx+OpenGL)
    要找工作了,研究工作得暂停了
    MC+多个emitter成功把撕裂场景基本解决了
    鸭梨很大
    这世界好人多啊
    JS代码的格式化和压缩
    FusionCharts使用实例
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7181323.html
Copyright © 2011-2022 走看看