zoukankan      html  css  js  c++  java
  • Codeforces Round #487 (Div. 2)C. A Mist of Florescence(思维)

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
    As the boat drifts down the river, a wood full of blossoms shows up on the riverfront.

    "I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."

    "What is it like?"

    "Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"

    There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.

    The wood can be represented by a rectangular grid of nn rows and mm columns. In each cell of the grid, there is exactly one type of flowers.

    According to Mino, the numbers of connected components formed by each kind of flowers are aabbcc and dd respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.

    You are to help Kanno depict such a grid of flowers, with nn and mm arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.

    Note that you can choose arbitrary nn and mm under the constraints below, they are not given in the input.

    Input

    The first and only line of input contains four space-separated integers aabbcc and dd (1a,b,c,d1001≤a,b,c,d≤100) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

    Output

    In the first line, output two space-separated integers nn and mm (1n,m501≤n,m≤50) — the number of rows and the number of columns in the grid respectively.

    Then output nn lines each consisting of mm consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively.

    In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

    Examples
    input
    Copy
    5 3 2 1
    
    output
    Copy
    4 7
    DDDDDDD
    DABACAD
    DBABACD
    DDDDDDD
    input
    Copy
    50 50 1 1
    
    output
    Copy
    4 50
    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
    ABABABABABABABABABABABABABABABABABABABABABABABABAB
    BABABABABABABABABABABABABABABABABABABABABABABABABA
    DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
    input
    Copy
    1 6 4 5
    
    output
    Copy
    7 7
    DDDDDDD
    DDDBDBD
    DDCDCDD
    DBDADBD
    DDCDCDD
    DBDBDDD
    DDDDDDD
    Note

    In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.

    思路:其实我们可以让每次都输出50*50的方阵,先将矩阵变为下图

    这样,然后联通块的话我们可以每次只涂一个,而且不改变整体的连通性,去掉边界一共24个减掉一半数量为12*12>100(题意),可行(看不懂的话可以看一下代码,很简单的)

    AC code:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    char Map[51][51];
    
    void init()
    {
        for (int i = 1;i<=50;i++){
            for (int j = 1;j<=50;j++){
                if( i<=25 && j<=25) Map[i][j] = 'A';
                if( i<=25 && j>25 ) Map[i][j] = 'B';
                if( i>25 && j<=25 ) Map[i][j] = 'C';
                if( i>25 && j>25 )  Map[i][j] = 'D';
            }
        }
    }
    
    int main()
    {
        init();
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d); 
        a -= 1, b -= 1,c -= 1, d -= 1;
        for (int i = 1;i<=25;i += 2){
            for (int j = 27;j<=50;j += 2){
                if(a == 0) break;
                else {
                    Map[i][j] = 'A';
                    a--;
                }
            }
            if(a == 0) break;
        }
        for (int i = 1;i<=24;i+=2){
            for (int j = 1;j<=24;j+=2){
                if(b == 0) break;
                else {
                    Map[i][j] = 'B';
                    b--;
                }
            }
            if(b == 0) break;
        }
        for (int i = 27;i<=50;i+=2){
            for (int j = 27;j<=50;j+=2){
                if (c == 0) break;
                else {
                    Map[i][j] = 'C';
                    c--;
                }
            }
            if (c == 0) break;
        }
        for (int i = 27;i<=50;i+=2){
            for (int j = 1;j<=24;j+=2){
                if(d == 0) break;
                else {
                    Map[i][j] = 'D';
                    d--;
                }
            }
            if (d == 0) break;
        }
        printf("50 50
    ");
        for (int i = 1;i<=50;i++){
            for (int j = 1;j<=50;j++){
                printf("%c",Map[i][j]);
            }
            printf("
    ");
        }
        return 0;
    }
    

     

     

     

  • 相关阅读:
    IntelliJ IDEA AndroidStudio SVN无法使用
    三极管封装
    STC等单片机一开机就停电模式烧写程序办法
    CC2541设置中断输入模式
    C# WinForm 多线程 应用程序退出的方法 结束子线程
    CorelDrawX8安装时提示已安装另一个版本
    Win10下Prolific USB-to-Serial Comm Port驱动提示不能使用
    Keil5创建GPIO
    SQL行列转置
    Excel复制粘贴假死
  • 原文地址:https://www.cnblogs.com/Nlifea/p/11745986.html
Copyright © 2011-2022 走看看