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

C. A Mist of Florescence

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 aa, bb, cc 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 aa, bb, cc and dd (1≤a,b,c,d≤1001≤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 (1≤n,m≤501≤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

题意:给你四个数,分别代表四种颜色的块数,你需要构造一个矩形,包含给定的块数。

思路:构造方式有很多,我这种可能麻烦- -。

1.开一个50*50的全‘D’矩形,然后在这上面抠图,首先把A和B抠出来,比如第一行间隔一个放A,第二行放B,第三行再放A,AB最多共计200个,也就占用前10行左右。

2.现在只剩下CD的问题了,C的构造将决定D的个数,所以此时麻烦些了。

CCC

CDC

CCC

构造这样的3*3图形,将剩余的40*50的位置全部构造出这个图形,注意上下左右相邻的3*3图形隔开一行或一列。

此时就好办了:如果D数目多了,将最中间那个D变成C即可消去一个,如果C数目多了,我们不是隔一行或一列吗,在那里填一个C,相邻的3*3图形就合成一个了,即消去一个。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define exp 1e-8
#define mst(a,k) memset(a,k,sizeof(a))
#define pi acos(-1.0)
using namespace std;
char mp[60][60];
ll a,b,c,d;
int main()
{
    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d))
    {
        for(ll i=1;i<=50;i++)   //全D矩阵
        {
            for(ll j=1;j<=50;j++)
            {
                mp[i][j]='D';
            }
        }
        for(ll i=1;i<=50;i+=2)   //每隔一个放A
        {
            for(ll j=1;j<=50;j+=2)
            {
                if(a)
                {
                    mp[i][j]='A';
                    a--;
                }
                else break;
            }
            if(a==0)break;
        }
        for(ll i=2;i<=50;i+=2)   //每隔一个放B
        {
            for(ll j=1;j<=50;j+=2)
            {
                if(b)
                {
                    mp[i][j]='B';
                    b--;
                }
                else break;
            }
            if(b==0)break;
        }
        for(ll i=10;i<=45;i+=4)   //构造3*3的图形
        {
            for(ll j=1;j<=45;j+=4)
            {
                mp[i][j]=mp[i][j+1]=mp[i][j+2]=mp[i+1][j]=mp[i+2][j]=mp[i+1][j+2]=mp[i+2][j+2]=mp[i+2][j+1]='C';
            }
        }
        ll tmp=108-c;
        for(ll i=12;i<=47;i+=4)   //消去多余的C图形
        {
            for(ll j=4;j<=45;j+=4)
            {
                if(tmp)
                {
                    mp[i][j]='C';
                    tmp--;
                }
                else break;
            }
            if(tmp==0)break;
            mp[i+1][1]='C';
            tmp--;
        }
        tmp=108-d+1;
        for(ll i=11;i<=46;i+=4)   //消去多余的D图形
        {
            for(ll j=2;j<=46;j+=4)
            {
                if(tmp)
                {
                    mp[i][j]='C';
                    tmp--;
                }
                else break;
            }
            if(tmp==0)break;
        }
        printf("50 50\n");
        for(ll i=1;i<=50;i++)
        {
            for(ll j=1;j<=50;j++)
            {
                printf("%c",mp[i][j]);
            }
            printf("\n");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/s540239976/article/details/81112650