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;

}


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