codeforces 980B Marlin

Title:

There is a city with 4 rows and n columns, n is an odd number, there is a village at (1,1), and the activity location of the villagers is (4,n);

There is a village at (4,1), and the villager's activity location is (1,n);

Now there are k hotels to be built, but they cannot be built on the boundary. Can you provide an arrangement so that the number of shortest paths between the villagers of the two villages to their respective activity locations is equal.

Ideas:

After drawing a few examples, you should know that no matter what n and k are, a reasonable solution can be constructed, so it is all YES.

If k is an even number, then it is symmetrical up and down, which is better to construct; when k is an odd number, what I use is to first fill the second row from the middle to both sides, and then the third row starts from both sides of the middle grid fill.

The case where k is 0 is ignored, resulting in n sending wa and n sending rte, miserable!

Code:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <string>
 4 #include <iostream>
 5 using namespace std;
 6 string a[4];
 7 int main()
 8 {
 9     int n,k;
10     scanf("%d%d",&n,&k);
11     puts("YES");
12     for (int i = 0;i < 4;i++)
13     {
14         for (int j = 0;j < n;j++) a[i].push_back('.');
15     }
16     if (k % 2 == 0)
17     {
18         int c = 1;
19         int l = 1;
20         while (1)
21         {
22             if (k <= 0) break;
23             a[c][l] = '#';
24             c++;
25             k--;
26             if (k <= 0) break;
27             if (c >= 3)
28             {
29                 c = 1;
30                 l++;
31             }
32         }
33     }
34     else
35     {
36         int l = n / 2,r = n / 2;
37         int c = 1;
38         while (1)
39         {
40             if (k <= 0) break;
41             a[c][l] = a[c][r] = '#';
42             if (l == r) k--;
43             else k-= 2;
44             if (k <= 0) break;
45             l--,r++;
46             if (l <= 0) break;
47         }
48         l =  n / 2 - 1,r = n / 2 + 1;
49         c = 2;
50         while (1)
51         {
52             if (k <= 0) break;
53             a[c][l] = a[c][r] = '#';
54             k -= 2;
55             l--,r++;
56         }
57     }
58     for (int i = 0;i < 4;i++) cout << a[i] << endl;
59     return 0;
60 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325988453&siteId=291194637