博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 989C (构造)
阅读量:5279 次
发布时间:2019-06-14

本文共 3984 字,大约阅读时间需要 13 分钟。

题面:

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 7DDDDDDDDABACADDBABACDDDDDDDD
input
Copy
50 50 1 1
output
Copy
4 50CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCABABABABABABABABABABABABABABABABABABABABABABABABABBABABABABABABABABABABABABABABABABABABABABABABABABADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
input
Copy
1 6 4 5
output
Copy
7 7DDDDDDDDDDBDBDDDCDCDDDBDADBDDDCDCDDDBDBDDDDDDDDDD
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,分别代表四个字符A,B,C,D,的连通分量的个数,让你去构造出最大为50*50的一个符合条件的图。

题目分析:

    我们可以考虑到如下的策略。首先我们可以确定将整张图初始化为两种字母,使得这两种字母的连通分量分别为。

    如n,m均为6时,可以先构造出:

A A A A A A
A A A A A A
A A A A A A
B B B B B B
B B B B B B
B B B B B B

这样的一个矩阵。

    其次,我们可以这么考虑,我们要使得C和D的连通分量增加,则我们就需要在图中的A更新成C或B,在原来图中的B更新成A或D。而要使得上下两块(A和B)的连通性不发生改变,我们就必须要间隔地进行更改,比如上述的图原来为.,我们要增加C的连通分量而使得原来A的不发生改变,则我们就需要将AAAA....变成CACA....即可,即变成下面的表格:

C A C A C A
C A C A C A
A A A A A A

此时A的连通分量不会发生改变,同理B也进行如下操作即可。

    而因为最大题目所给的a,b,c,d,均不知道范围,因此我们就贪心地取最大就50即可。

代码:

#include 
using namespace std;char str[60][60];int main(){ int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); for(int i=0;i<50;i++){ for(int j=0;j<50;j++){ if(i>25){ str[i][j]='B'; } else str[i][j]='A'; } } a--,b--; for(int i=0;i<25;i+=2){ for(int j=0;j<50;j+=2){ if(b){ str[i][j]='B'; b--; } else if(c){ str[i][j]='C'; c--; } } } for(int i=27;i<50;i+=2){ for(int j=0;j<50;j+=2){ if(a){ str[i][j]='A'; a--; } else if(d){ str[i][j]='D'; d--; } } } puts("50 50"); for(int i=0;i<50;i++){ puts(str[i]); } return 0;}

转载于:https://www.cnblogs.com/Chen-Jr/p/11007275.html

你可能感兴趣的文章
Java中的Random()函数
查看>>
多线程NSThread基本用法
查看>>
jstl-随机数-借用jsp嵌入的代码
查看>>
云变换算法
查看>>
C#创建socket服务
查看>>
小智慧38
查看>>
【译】x86程序员手册01
查看>>
CDI server decorstors intercepters scope EL eventmodel
查看>>
软件测试homework1
查看>>
第六次课程作业:随笔
查看>>
行列式,线性变换,变换,雅克比行列式,二次型
查看>>
文件写入和读取
查看>>
物理学中的几何方法笔记
查看>>
dtree实现动态加载树形菜单,动态插入树形菜单
查看>>
如何在java List中进行模糊查询
查看>>
定制一套属于自己的博客样式
查看>>
ArcGIS自定义工具箱-字段值部分替换
查看>>
eclipse的安装和汉化
查看>>
【NumberValidators】大陆身份证验证
查看>>
C语言实现字符串IP与整数型IP的相互转换
查看>>