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 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
Note
In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.
题解
借用大佬的图片:
在这里插入图片描述
连通块问题,解题关键在于构造,构造好矩阵解题就没有任何困难了
矩阵构造50*50,平均分为四块分别填充ABCD构成连通块
接下来只需要在保证初始的四块连通块的连通性的同时插入另外的颜色即可。
代码

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std; 
char mmp[50][50];
void push(int stx,int enx, int sty, int eny, char str)
{
    for(int i = stx; i < enx; i ++) {
        for(int j = sty; j < eny; j ++) {
            mmp[i][j] = str;
        }
    }
}
int main(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    a -= 1;
    b -= 1;
    c -= 1;
    d -= 1;
    push(0, 25, 0, 25, 'B');//初始化
    push(0, 25, 25, 50, 'A');
    push(25, 50, 0, 25, 'D');
    push(25, 50, 25, 50, 'C');
    for(int i = 0; i < 25&&a; i ++) {
        for(int j = 0; j < 25&&a; j ++) {
            if(i%2 && j%2) {
                mmp[i][j] = 'A';
                a --;
            }
        }
    }//完全的复制粘贴,稍微改一下就可以应用在四个连通块上,简单粗暴
    for(int i = 0; i < 25&&b; i ++) {
        for(int j = 25; j < 50&&b; j ++) {
            if(i%2 == 0 && j%2 == 0) {
                mmp[i][j] = 'B';
                b --;
            }
        }
    }
    for(int i = 25; i < 50&&c; i ++) {
        for(int j = 0; j < 25&&c; j ++) {
            if(i%2 && j%2) {
                mmp[i][j] = 'C';
                c --;
            }
        }
    }
    for(int i = 25; i < 50&&d; i ++) {
        for(int j = 25; j < 50&&d; j ++) {
            if(i%2 == 0 && j%2 == 0) {
                mmp[i][j] = 'D';
                d --;
            }
        }
    }
    cout<<"50 50"<<endl;
    for(int i = 0; i < 50;  i++) {
        for(int j = 0; j < 50; j ++) {
            cout<<mmp[i][j];
        }
        cout<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值