Codeforces Round #487 (Div. 2) C. A Mist of Florescence

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.

題意:構造題,上下左右相連的爲一塊,輸入A,B,C,D的塊數要你構造一個n*m的正方形方格,注意塊數1<=n<100,n和m小於=50

題解:直接令n=m=50,把它分成四塊,分別填B,A,D,C,然後再在每個大塊中插入其他小塊,每上下左右隔一個插一個直到把a-1個A全插入到b中,特別注意一下i==24時,B中的A會和第二部分A連在一起導致出錯,集體看代碼

代碼:

#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int M = 3e5+10;
char s[50][50];
int main()
{
    int a,b,c,d;
    ios::sync_with_stdio(false);
    cin>>a>>b>>c>>d;
    cout<<50<<" "<<50<<endl;
    int i,j;
    f(i,0,25)
    {
        f(j,0,25)
            s[i][j]='B';
        f(j,25,50)
            s[i][j]='A';
    }
    f(i,25,50)
    {
        f(j,0,25)
            s[i][j] = 'D';
        f(j,25,50)
            s[i][j]='C';
    }
    a--,b--,c--,d--;
    f(i,0,25)
    {
        if(a==0)
            break;
        f(j,0,25)
        {
            if(a==0)
                break;
                
            if(i%2==0&&j%2==0&&j!=24)
            {
                s[i][j]='A';
                a--;
            }
        }
    }
    f(i,0,25)
    {
        if(b==0)
            break;
        f(j,25,50)
        {
            if(b==0)
                break;
            if(i%2==0&&j%2==0)
            {
                s[i][j]='B';
                b--;
            }
        }
    }
    f(i,25,50)
    {
        if(c==0)
            break;
        f(j,0,25)
        {
            if(c==0)
                break;
            if(i%2==0&&j%2==0&&j!=24)
            {
                s[i][j]='C';
                c--;
            }
        }
    }
    f(i,25,50)
    {
        if(d==0)
            break;
        f(j,25,50)
        {
            if(d==0)
                break;
            if(i%2==0&&j%2==0)
            {
                s[i][j]='D';
                d--;
            }
        }
    }
    f(i,0,50)
    {
        f(j,0,50)
            cout<<s[i][j];
        cout<<endl;
    }
    return 0;

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章