Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)
Posted qldabiaoge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)相关的知识,希望对你有一定的参考价值。
"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.
The 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.
In 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).
5 3 2 1
4 7
DDDDDDD
DABACAD
DBABACD
DDDDDDD
50 50 1 1
4 50
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ABABABABABABABABABABABABABABABABABABABABABABABABAB
BABABABABABABABABABABABABABABABABABABABABABABABABA
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
1 6 4 5
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.
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<string> 5 #include<cstring> 6 using namespace std; 7 typedef long long LL; 8 const int maxn = 3e5 + 10; 9 10 char tu[55][55]; 11 int num[10]; 12 int dx[4] = {0, 0, 1, -1}; 13 int dy[4] = {1, -1, 0, 0}; 14 int check(int i, int j ) { 15 if (i < 0 || i >= 50 || j < 0 || j >= 50) return 0; 16 return 1; 17 } 18 int check1(int i, int j, char cnt ) { 19 for (int k = 0 ; k < 4 ; k++) { 20 int nx = i + dx[k]; 21 int ny = j + dy[k]; 22 // printf("%c %c ",tu[nx][ny],cnt); 23 if (check(nx, ny)) { 24 if (tu[nx][ny] == cnt) return 0; 25 } 26 } 27 return 1; 28 } 29 int main() { 30 char s[10] = "ABCD"; 31 scanf("%d%d%d%d", &num[0], &num[1], &num[2], &num[3]); 32 for (int i = 0 ; i < 50 ; i++) { 33 for (int j = 0 ; j < 50 ; j++) { 34 if (i < 25 && j < 25) tu[i][j] = ‘A‘; 35 if (i < 25 && j >= 25) tu[i][j] = ‘B‘; 36 if (i >= 25 && j < 25) tu[i][j] = ‘C‘; 37 if (i >= 25 && j >= 25) tu[i][j] = ‘D‘; 38 } 39 } 40 if (num[0] - 1) { 41 int cnt = 1; 42 for (int i = 0 ; i < 50 ; i++) { 43 for (int j = 0 ; j < 50 ; j++) { 44 if (i >= 25 && j >= 25) { 45 int sum = 0; 46 for (int k = 25 ; k < 50 ; k++) { 47 if (tu[i - 1][k] == ‘A‘) sum++; 48 } 49 if (sum > 12) break; 50 if (tu[i][j] == ‘D‘ && check1(i, j, s[0] ) ) { 51 tu[i][j] = ‘A‘; 52 cnt++; 53 } 54 if (cnt == num[0]) break; 55 } 56 } 57 if (cnt == num[0]) break; 58 } 59 } 60 if (num[1] - 1) { 61 int cnt = 1; 62 for (int i = 0 ; i < 50 ; i++) { 63 for (int j = 0 ; j < 50 ; j++) { 64 if (i >= 25 && j < 25) { 65 int sum = 0; 66 for (int k = 0 ; k < 25 ; k++) { 67 if (tu[i - 1][k] == ‘B‘) sum++; 68 } 69 if (sum > 12) break; 70 if (tu[i][j] == ‘C‘ && check1(i, j, s[1]) ) { 71 tu[i][j] = ‘B‘; 72 cnt++; 73 } 74 } 75 if (cnt == num[1]) break; 76 } 77 if (cnt == num[1]) break; 78 } 79 } 80 if (num[2] - 1) { 81 int cnt = 1; 82 for (int i = 0 ; i < 50 ; i++) { 83 for (int j = 0 ; j < 50 ; j++) { 84 if (i < 25 && j >= 25) { 85 int sum = 0; 86 for (int k = 25 ; k < 50 ; k++) { 87 if (tu[i - 1][k] == ‘C‘) sum++; 88 } 89 if (sum > 12) break; 90 if (tu[i][j] == ‘B‘ && check1(i, j, s[2]) ) { 91 tu[i][j] = ‘C‘; 92 cnt++; 93 } 94 } 95 if (cnt == num[2]) break; 96 } 97 if (cnt == num[2]) break; 98 } 99 } 100 if (num[3] - 1) { 101 int cnt = 1; 102 for (int i = 0 ; i < 50 ; i++) { 103 for (int j = 0 ; j < 50 ; j++) { 104 if (i < 25 && j < 25) { 105 int sum = 0; 106 for (int k = 0 ; k < 25 ; k++) { 107 if (tu[i - 1][k] == ‘D‘) sum++; 108 } 109 if (sum > 12) break; 110 if (tu[i][j] == ‘A‘ && check1(i, j, s[3]) ) { 111 tu[i][j] = ‘D‘; 112 cnt++; 113 } 114 } 115 if (cnt == num[3]) break; 116 } 117 if (cnt == num[3]) break; 118 } 119 } 120 printf("50 50 "); 121 for (int i = 0 ; i < 50 ; i++) 122 printf("%s ", tu[i]); 123 return 0; 124 }
以上是关于Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #487 (Div. 2) C - A Mist of Florescence
Codeforces Round #487 (Div. 2) C - A Mist of Florescence
Codeforces Round #436 E. Fire(背包dp+输出路径)