C - A Mist of Florescence CodeForces - 989C

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 n rows and m 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 a, b, c and d 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 n and m 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 n and m under the constraints below, they are not given in the input.

Input
The first and only line of input contains four space-separated integers a, b, c and d (1≤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 n and m (1≤n,m≤50) — the number of rows and the number of columns in the grid respectively.

Then output n lines each consisting of m 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.

扫描二维码关注公众号,回复: 2695390 查看本文章

In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

Examples
Input
5 3 2 1
Output
4 7
DDDDDDD
DABACAD
DBABACD
DDDDDDD
Input
50 50 1 1
Output
4 50
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ABABABABABABABABABABABABABABABABABABABABABABABABAB
BABABABABABABABABABABABABABABABABABABABABABABABABA
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
Input
1 6 4 5
Output
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个A块,b个B块,c个C块,d个D块,方法有很多,但是只要输出任意一种方法就可以。我一开始没想出来(我真羡慕那些有脑子的人),卡了很久。方法如下:
题目要求n,m都小于50,那么我们就尽量取大一点好了,取n=48,m=50,则根据样例的图片,我们可以把整个grid分成4个部分:
填充A区域的12行
填充B区域的12行
填充C区域的12行
填充D区域的12行
然后在A区域填b,在B区域填c,在C区域填d,在D区域填a
填充的方法是每填充一个格子空一个格子,每填充一个格子空一行。

Accepted code:

#include<iostream>
using namespace std;

static const int maxn=55;
int a,b,c,d;
char grid[maxn][maxn];

void init()
{
    for(int i=0;i<48;i++)
        for(int j=0;j<50;j++)
            grid[i][j]='A'+i/12;
}

void scatter_fill()
{
    a--;
    b--;
    c--;
    d--;
    int cnt=0;
    for(int i=0;i<12&&cnt<b;i+=2)
    {
        for(int j=0;j<50&&cnt<b;j+=2)
        {
            grid[i][j]='B';
            cnt++;
        }
    }
    cnt=0;
    for(int i=12;i<24&&cnt<c;i+=2)
    {
        for(int j=0;j<50&&cnt<c;j+=2)
        {
            grid[i][j]='C';
            cnt++;
        }
    }
    cnt=0;
    for(int i=24;i<48&&cnt<d;i+=2)
    {
        for(int j=0;j<50&&cnt<d;j+=2)
        {
            grid[i][j]='D';
            cnt++;
        }
    }
    cnt=0;
    for(int i=36;i<48&&cnt<a;i+=2)
    {
        for(int j=0;j<50&&cnt<a;j+=2)
        {
            grid[i][j]='A';
            cnt++;
        }
    }
}

void print()
{
    cout<<"48 50"<<endl;
    for(int i=0;i<48;i++)
        for(int j=0;j<50;j++)
        {
            if(j<49)
                cout<<grid[i][j];
            else
                cout<<grid[i][j]<<endl;
        }
}

int main()
{
    cin>>a>>b>>c>>d;
    init();
    scatter_fill();
    print();
}

猜你喜欢

转载自blog.csdn.net/QingyingLiu/article/details/80700094
今日推荐