codeforces 989C A Mist of Florescence

http://www.elijahqi.win/archives/3662
题目描述
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

n rows and

m

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

a ,

b

b ,

c

c and

d

drespectively. 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

n and

m

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

n and

m

m under the constraints below, they are not given in the input.

输入输出格式
输入格式:

The first and only line of input contains four space-separated integers

a

a ,

b

b ,

c

c and

d

d (

1 \leq a, b, c, d \leq 100

1≤a,b,c,d≤100 ) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

输出格式:

In the first line, output two space-separated integers

n

n and

m

m (

1 \leq n, m \leq 50

1≤n,m≤50 ) — the number of rows and the number of columns in the grid respectively.

Then output

n

n lines each consisting of

m

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.

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

输入输出样例
输入样例#1: 复制

5 3 2 1
输出样例#1: 复制

4 7
DDDDDDD
DABACAD
DBABACD
DDDDDDD
输入样例#2: 复制

50 50 1 1
输出样例#2: 复制

4 50
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ABABABABABABABABABABABABABABABABABABABABABABABABAB
BABABABABABABABABABABABABABABABABABABABABABABABABA
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
输入样例#3: 复制

1 6 4 5
输出样例#3: 复制

7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD
说明
In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.

考虑构造四个 区域 每个区域长度为50 宽度为9 然后类似三明治一样 考虑往中间i填写 往A里面 填写 B 往B里面填写A 然后这样恰好可以满足要求 即使4个100 用最多 36行也可以满足条件

形如

AAA

ABA

AAA

ABA

AAA

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c,d;
char mp[55][55];
int main(){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    puts("36 50");
    --a;--b;--c;--d;
    for (int i=1;i<=9;++i) 
        for (int j=1;j<=50;++j) mp[i][j]='a';
    for (int i=10;i<=18;++i)
        for (int j=1;j<=50;++j) mp[i][j]='b';
    for (int i=19;i<=27;++i)
        for (int j=1;j<=50;++j) mp[i][j]='c';
    for (int i=28;i<=36;++i)
        for (int j=1;j<=50;++j) mp[i][j]='d';
    int cnt=0;bool flag=0;
    if (b){
        for (int i=2;i<=8;i+=2){
            for (int j=2;j<=50;j+=2){
                ++cnt;mp[i][j]='b';if (cnt==b) {flag=1;break;}  
            }if(flag) break;
        }
    }cnt=0;flag=0;
    if (a){
        for (int i=11;i<=17;i+=2){
            for (int j=2;j<=50;j+=2){
                ++cnt;mp[i][j]='a';if (cnt==a) {flag=1;break;}  
            }if (flag) break;
        }
    }cnt=0;flag=0;
    if (d){
        for (int i=20;i<=26;i+=2){
            for (int j=2;j<=50;j+=2){
                ++cnt;mp[i][j]='d';if (cnt==d) {flag=1;break;}  
            }if (flag) break;
        }
    }cnt=0;flag=0;
    if (c){
        for (int i=29;i<=35;i+=2){
            for (int j=2;j<=50;j+=2){
                ++cnt;mp[i][j]='c';if (cnt==c) {flag=1;break;}  
            }if (flag) break;
        }
    }
    for (int i=1;i<=36;++i){
        for (int j=1;j<=50;++j) putchar(mp[i][j]);puts("");
    }
    return 0;
}
发布了1259 篇原创文章 · 获赞 22 · 访问量 13万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览