zoukankan      html  css  js  c++  java
  • CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contempted.The problem in Div2 was so...em,how to say,anyway I even daren't to believe.Yesterday I solved two fifths of problems.You see? I'm just a guy full of oration.But it is for sure that the two question I worked out yesterday and the other one today morning,their simplicity was out of my imagine.
     
    A. Cakeminator
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows:

     

    The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.

    Please output the maximum number of cake cells that the cakeminator can eat.

    Input

    The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these:

    • '.' character denotes a cake cell with no evil strawberry;
    • 'S' character denotes a cake cell with an evil strawberry.
    Output

    Output the maximum number of cake cells that the cakeminator can eat.

    Sample test(s)
    Input
    3 4
    
    

    S...

    ....

    ..S.
    Output
    8
    Note

    For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).

     

    #include<stdio.h>
    #include<string.h>
    int r,c;
    char ch[15][15];
    bool g[15][15];
    bool judger(int x)
    {
        int i;
        for (i=0;i<c;i++)
        if (ch[x][i]=='S') return false;
        return true;
    }
    bool judgec(int x)
    {
        int i;
        for (i=0;i<r;i++)
        if (ch[i][x]=='S') return false;
        return true;
    }
    int main()
    {
        while (scanf("%d%d",&r,&c)!=EOF)
        {
            int i,j;
            for (i=0;i<r;i++) scanf("%s",ch[i]);
            memset(g,0,sizeof(g));
            for (i=0;i<r;i++)
            if (judger(i))
                for (j=0;j<c;j++) g[i][j]=true;
            for (i=0;i<c;i++)
            if (judgec(i))
                for (j=0;j<r;j++) g[j][i]=true;
            int ans=0;
            for (i=0;i<r;i++)
             for (j=0;j<c;j++)
             if (g[i][j]) ans++;
            printf("%d
    ",ans);
        }
        return 0;
    }
    

     

     

     

    B. Road Construction
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.

    Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.

    Input

    The first line consists of two integers n and m .

    Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.

    It is guaranteed that every pair of cities will appear at most once in the input.

    Output

    You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.

    If there are several solutions, you may print any of them.

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

    This is one possible solution of the example:

     

    These are examples of wrong solutions:

    The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair.

     

    The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads.

     

    Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.

    At first I was scared by the description,because I didn't know how to handle it.But after a few minutes,I noticed that m<(n/2).That mean for each case ,there would exist a point which can draw a street with any other citise.So, the minimum of the roads must be n-1.Then just find a city above,and link it with all the other cities.

     

    #include<stdio.h>
    #include<string.h>
    bool s[1024];
    int main()
    {
        int N,M,u,v,i;
        while (scanf("%d%d",&N,&M)!=EOF)
        {
            memset(s,true,sizeof(s));
            for (i=1;i<=M;i++)
            {
                int u,v;
                scanf("%d%d",&u,&v);
                s[u]=false;
                s[v]=false;
            }
            printf("%d
    ",N-1);
            for (i=1;i<=N;i++)
            if (s[i])
            {
                u=i;
                break;
            }
            for (i=1;i<=N;i++)
            if (i!=u) printf("%d %d
    ",u,i);
        }
        return 0;
    }
     
    

     

     

     

  • 相关阅读:
    2019牛客暑期多校赛(第四场)
    单调栈求左右第一个比该数大(小)的位置
    带修莫队板子
    普通莫队算法
    2019牛客暑期多校赛(第三场)B-求01串中的最长01数量相等的子串和子序列
    2019牛客暑假多校赛(第二场) F和H(单调栈)
    网络文件系统nfs
    rsync详解
    逻辑卷LVM
    crontab定时任务
  • 原文地址:https://www.cnblogs.com/dramstadt/p/3203383.html
Copyright © 2011-2022 走看看