CF989C A Mist of Florescence

思路:

有趣的构造题。

实现:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char ans[51][51];
 4 void fillin(int x, int y, char c, int maxy, int cnt)
 5 {
 6     int a = x, b = y;
 7     while (cnt)
 8     {
 9         ans[a][b] = c;
10         if (b + 2 >= maxy) { a += 2; b = y; }
11         else b += 2;
12         cnt--;
13     }
14 }
15 int main()
16 {
17     int a, b, c, d;
18     while (cin >> a >> b >> c >> d)
19     {
20         for (int i = 0; i < 25; i++)
21         {
22             for (int j = 0; j < 25; j++)
23             {
24                 ans[i][j] = 'A';
25                 ans[i][j + 25] = 'B';
26                 ans[i + 25][j] = 'C';
27                 ans[i + 25][j + 25] = 'D';
28             }
29         }
30         fillin(1, 1, 'B', 25, b - 1);
31         fillin(1, 26, 'C', 50, c - 1);
32         fillin(26, 1, 'D', 25, d - 1);
33         fillin(26, 26, 'A', 50, a - 1);
34         cout << "50 50" << endl;
35         for (int i = 0; i < 50; i++)
36         {
37             for (int j = 0; j < 50; j++)
38                 cout << ans[i][j];
39             cout << endl;
40         }
41     }
42     return 0;
43 }

总结:

对于构造题,要尽量用简单的方法完成任务,不要自己徒增限制条件。

猜你喜欢

转载自www.cnblogs.com/wangyiming/p/9173082.html
今日推荐