首页 > 其他 > 详细

agc033

时间:2019-05-08 10:59:45      阅读:302      评论:0      收藏:0      [点我收藏+]

A题意:给你个黑白矩阵,每次黑的周围一圈会变黑,求多少次之后全黑。n <= 1000

解:BFS即可。

技术分享图片
 1 #include <bits/stdc++.h>
 2  
 3 const int N = 1010;
 4 const int dx[] = {1, 0, -1, 0};
 5 const int dy[] = {0, 1, 0, -1};
 6  
 7 struct Node {
 8     int x, y;
 9     Node(int X = 0, int Y = 0) {
10         x = X;
11         y = Y;
12     }
13 };
14  
15 int vis[N][N], d[N][N];
16 char str[N];
17 std::queue<Node> Q;
18  
19 int main() {
20  
21     int n, m, ans = 0;
22     scanf("%d%d", &n, &m);
23     for(int i = 1; i <= n; i++) {
24         scanf("%s", str + 1);
25         for(int j = 1; j <= m; j++) {
26             if(str[j] == #) {
27                 Q.push(Node(i, j));
28                 vis[i][j] = 1;
29                 d[i][j] = 0;
30             }
31         }
32     }
33  
34     while(Q.size()) {
35         int x = Q.front().x, y = Q.front().y;
36         Q.pop();
37         for(int i = 0; i < 4; i++) {
38             int tx = x + dx[i], ty = y + dy[i];
39             if(tx < 1 || ty < 1 || tx > n || ty > m || vis[tx][ty]) {
40                 continue;
41             }
42             vis[tx][ty] = 1;
43             d[tx][ty] = d[x][y] + 1;
44             Q.push(Node(tx, ty));
45             ans = std::max(ans, d[tx][ty]);
46         }
47     }
48     printf("%d\n", ans);
49     return 0;
50 }
AC代码

B题意:给你个矩阵,初始时有个棋子在(sx,sy)。先后手都有个字符串,每一回合可以选择不走或者按照字符串上的方向走一步。先手想要玩完n回合,后手想要在n回合之内把棋子走出棋盘。谁能如愿以偿呢?n <= 10w

解:发现行列独立。于是考虑行。我们从后往前,维护第i步时棋子在哪些地方会导致在n步内出棋盘。判断一下是否必出棋盘即可。列同理。

技术分享图片
 1 #include <bits/stdc++.h>
 2 
 3 const int N = 200010;
 4 
 5 char str1[N], str2[N];
 6 int n;
 7 
 8 int main() {
 9 
10     int n1, n2, x1, x2;
11     scanf("%d%d%d", &n1, &n2, &n);
12     scanf("%d%d", &x1, &x2);
13     scanf("%s%s", str1 + 1, str2 + 1);
14 
15     bool f = 1;
16     int L = 0, R = n1 + 1;
17     for(int i = n; i >= 1; i--) {
18 
19         if(str2[i] == L || str2[i] == R) {
20 
21         }
22         else if(str2[i] == D) {
23             L = std::max(L - 1, 0);
24         }
25         else {
26             R = std::min(R + 1, n1 + 1);
27         }
28 
29         if(str1[i] == L || str1[i] == R) {
30 
31         }
32         else if(str1[i] == D) {
33             R = R - 1;
34         }
35         else {
36             L = L + 1;
37         }
38         if(L + 1 >= R) {
39             f = 0;
40             break;
41         }
42 
43     }
44     if(x1 <= L || R <= x1) {
45         f = 0;
46     }
47     L = 0, R = n2 + 1;
48     for(int i = n; i >= 1 && f; i--) {
49 
50         if(str2[i] == U || str2[i] == D) {
51 
52         }
53         else if(str2[i] == L) {
54             R = std::min(R + 1, n2 + 1);
55         }
56         else {
57             L = std::max(L - 1, 0);
58         }
59 
60         if(str1[i] == U || str1[i] == D) {
61 
62         }
63         else if(str1[i] == L) {
64             L = L + 1;
65         }
66         else {
67             R = R - 1;
68         }
69         if(L + 1 >= R) {
70             f = 0;
71             break;
72         }
73 
74     }
75     if(x2 <= L || R <= x2) {
76         f = 0;
77     }
78     if(f) {
79         printf("YES\n");
80     }
81     else {
82         printf("NO\n");
83     }
84     return 0;
85 }
AC代码

C题意:

agc033

原文:https://www.cnblogs.com/huyufeifei/p/10830406.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!