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四个字母的联通分量数,然后,让你在一个最大50*50的矩形内实现这种连通。只有相同颜色的挨着,才算连通。输出连通的图的样子。

思路:

我的思路麻烦了,是按照给的数字的大小,定好图的大小,然后再差不多按照例子的格式填充。但是这种题,根本不需判断,直接填充满50*50就好。

代码:

#include <bits/stdc++.h>

using namespace std;
const int maxn=110;
char ma[maxn][maxn];
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int sum_ab=max(a/23,b/23)+1;
    int sum_cd=max(c/23,d/23)+1;
    int tu1=0,tu2=0;
    if(a>b)a-=1,tu1=1;
    else b-=1,tu1=2;
    if(c>d)c-=1,tu2=3;
    else d-=1,tu2=4;
    int max_1=max(a,max(b,max(c,d)));
    int sum=sum_ab+sum_cd;
    int a1=0,b1=0,c1=0,d1=0;
    char q;
    int ans=0;
    max_1*=2;
    if(max_1>24)max_1=23*2;
    for(int i=1;i<=sum*3;i+=3)
    {
        ans++;
        if(ans<=sum_ab)
        {
        if(tu2==3)q='c';
        else q='d';
        for(int j=0;j<=max_1+1;j++)ma[i][j]=q;
        for(int j=1;j<=max_1;j++)
        {
            if(j%2==1&&a1<=a-1)ma[i+1][j]='a',a1++;
            if(j%2==0&&b1<=b-1)ma[i+1][j]='b',b1++;
        }
        for(int j=0;j<=max_1+1;j++)ma[i+2][j]=q;
        for(int j=0;j<=max_1+1;j++)
        {
            if(ma[i+1][j]!='a'&&ma[i+1][j]!='b')ma[i+1][j]=q;
        }
        }
        else
        {
        if(tu1==1)q='a';
        else q='b';
        for(int j=0;j<=max_1+1;j++)ma[i][j]=q;
        for(int j=1;j<=max_1;j++)
        {
            if(j%2==1&&c1<=c-1)ma[i+1][j]='c',c1++;
            if(j%2==0&&d1<=d-1)ma[i+1][j]='d',d1++;
        }
        for(int j=0;j<=max_1+1;j++)ma[i+2][j]=q;
        for(int j=0;j<=max_1+1;j++)
        {
            if(ma[i+1][j]!='c'&&ma[i+1][j]!='d')ma[i+1][j]=q;
        }
        }
    }
    printf("%d %d\n",sum*3,max_1+2);
    for(int i=1;i<=sum*3;i++)
    {
        for(int j=0;j<=max_1+1;j++)
        {
            printf("%c",ma[i][j]);
        }
        printf("\n");
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值