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 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.
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.
Output
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).
Examples
input
5 3 2 1
output
4 7DDDDDDDDABACADDBABACDDDDDDDD
input
50 50 1 1
output
4 50CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCABABABABABABABABABABABABABABABABABABABABABABABABABBABABABABABABABABABABABABABABABABABABABABABABABABADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
input
1 6 4 5
output
7 7DDDDDDDDDDBDBDDDCDCDDDBDADBDDDCDCDDDBDBDDDDDDDDDD
Note
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\n",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\n"); 121 for (int i = 0 ; i < 50 ; i++) 122 printf("%s\n", tu[i]); 123 return 0; 124 }
View
原文地址:https://www.cnblogs.com/qldabiaoge/p/9172180.html