Codeforces 989C (构造)
傳送門(mén)
題面:
C. A Mist of Florescencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs 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.
InputThe 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.
OutputIn 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).
ExamplesinputCopy5 3 2 1 outputCopy4 7 DDDDDDD DABACAD DBABACD DDDDDDDinputCopy50 50 1 1 outputCopy4 50 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ABABABABABABABABABABABABABABABABABABABABABABABABAB BABABABABABABABABABABABABABABABABABABABABABABABABA DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDinputCopy1 6 4 5 outputCopy7 7 DDDDDDD DDDBDBD DDCDCDD DBDADBD DDCDCDD DBDBDDD DDDDDDDNoteIn the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.
題目描述:
? ? 給你四個(gè)數(shù)a,b,c,d,分別代表四個(gè)字符A,B,C,D,的連通分量的個(gè)數(shù),讓你去構(gòu)造出最大為50*50的一個(gè)符合條件的圖。
題目分析:
? ? 我們可以考慮到如下的策略。首先我們可以確定將整張圖初始化為兩種字母,使得這兩種字母的連通分量分別為。
? ? 如n,m均為6時(shí),可以先構(gòu)造出:
| 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 |
這樣的一個(gè)矩陣。
? ? 其次,我們可以這么考慮,我們要使得C和D的連通分量增加,則我們就需要在圖中的A更新成C或B,在原來(lái)圖中的B更新成A或D。而要使得上下兩塊(A和B)的連通性不發(fā)生改變,我們就必須要間隔地進(jìn)行更改,比如上述的圖原來(lái)為.,我們要增加C的連通分量而使得原來(lái)A的不發(fā)生改變,則我們就需要將AAAA....變成CACA....即可,即變成下面的表格:
| C | A | C | A | C | A |
| C | A | C | A | C | A |
| A | A | A | A | A | A |
此時(shí)A的連通分量不會(huì)發(fā)生改變,同理B也進(jìn)行如下操作即可。
? ? 而因?yàn)樽畲箢}目所給的a,b,c,d,均不知道范圍,因此我們就貪心地取最大就50即可。
代碼:
#include <bits/stdc++.h> 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; }轉(zhuǎn)載于:https://www.cnblogs.com/Chen-Jr/p/11007275.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces 989C (构造)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: win下python环境搭建以及安装pi
- 下一篇: 在Java中动态传参调用Python脚本