Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)

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

时间: 2024-10-15 08:55:01

Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)的相关文章

Codeforces Round #487 (Div. 2) C - A Mist of Florescence

传送门:http://codeforces.com/contest/989/problem/C 这是一个构造问题. 构造一张网格,网格中的字符为'A'.'B'.'C'.'D',并且其连通块的个数分别为a.b.c.d. 首先我们可以考虑两种颜色的情形: 构造一张网格,网格中的字符为'0'.'1',并且其连通块的个数分别为a.b,其中a.b均为正整数.于是,至少为'0'.'1'分别构造一个连通块:再分别以连通块为"网",植入'1'.'0',植入时应保证植入的点互不连通.如下图所示: 以上构

Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】

任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call some square matrix with integer values in its cells palind

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

Codeforces Round #350 (Div. 2) F. Restore a Number 模拟构造题

F. Restore a Number Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shuffled in arbitrary order while

Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力

A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 Description Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindro

Codeforces Round #315 (Div. 2) C - Primes or Palindromes?(暴力打表)

题意:给一个p和q然后求π(n)?≤?p/q*rub(n),的最大的n值,其中π(n)?表示从1到n之间的素数的个数, rub(n)表示从1到n之间的回文数的个数(回文数不能有前导0,且从左到右和从右到左一样) 分析:其实这题没有题目没有确定n的范围让人不敢直接暴搜打表,但是你只要手动写个函数y=π(n)?/rub(n) 手动模拟暴力一下就可以发现其实这个函数大概是先下降后上升的,由于1/42<=p/q<=42,也就是说当y=42的时候就 是它的边界了,那么n的范围大概是1200000左右,取

Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造

链接:https://www.luogu.com.cn/problem/CF1243B2 题意:给你长度为n的两个字符串s和t,你可以最多进行2*n次操作,每次操作选择i和j,然后交换s[i]和t[j],问你能否使得两个字符串相同 构造方法:假如(0~i)部分s和t已经相等,在i位置时首先在(i+1~t.size()-1)里找有没有和t[i]相同的字符,如果找到,则交换s[i]和t[j],如果找不到,则在s中找,找到之后,先将s[j]与t[t.size()-1],交换,再将s[i]与t[t.si

Codeforces Round #401 (Div. 2) E 贪心,线段树

Codeforces Round #401 (Div. 2) A 循环节 B 暴力排一下 C 标记出来,但10^5,特耿直地码了个O(n^2)的上去,最气的是在最后3分钟的时候被叉== D 从后往前贪心暴糙一下就好.比赛时一眼瞄出来了不敢写,搞不懂这样竟然不会超时.. E. Hanoi Factory 题意:n个环体,内径a[i],外径b[i],高h[i].当 a[i+1]<b[i]<=b[i+1] 时,第 i 个环体可以堆在第 i+1个环体上.求可以堆出的最高高度. tags:佩服那些大佬,

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i