非原创codeforces 1063B Labyrinth 01bfs

Posted zmin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了非原创codeforces 1063B Labyrinth 01bfs相关的知识,希望对你有一定的参考价值。

学习博客:戳这里

附本人代码:

技术分享图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 2e3 + 10;
 5 const ll mod = 998244353;
 6 char st[maxn][maxn];
 7 int vis[maxn][maxn];
 8 int dx[11]={1,-1, 0, 0};
 9 int dy[11]={0, 0, 1,-1};
10 const int inf = 0x3f3f3f3f;
11 struct nod{
12     int x, y;
13 };
14 int main() {
15 
16     int n, m;
17     int r, c;
18     int X, Y;
19     scanf("%d %d", &n, &m);
20     scanf("%d %d", &r, &c);
21     scanf("%d %d", &X, &Y);
22     for(int i = 1; i <= n; ++i) {
23         scanf("%s", st[i]+1);
24     }
25     memset(vis, inf, sizeof(vis));
26     deque<nod>q;
27     nod u, v;
28     u.x = r, u.y = c;
29     q.push_front(u);
30     vis[u.x][u.y] = 0;
31     while(!q.empty()) {
32         u = q.front(); q.pop_front();
33         for(int i = 0; i < 4; ++i) {
34             int xx = u.x + dx[i];
35             int yy = u.y + dy[i];
36             if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && st[xx][yy] != *) {
37                 if(vis[u.x][u.y] + (i==2) < vis[xx][yy]) {
38                     vis[xx][yy] = vis[u.x][u.y] + (i==2);
39                     v.x = xx, v.y = yy;
40                     if(i == 2) q.push_back(v);
41                     else q.push_front(v);
42                 }
43             }
44         }
45     }
46     int ans = 0;
47     for(int i = 1; i <= n; ++i) {
48         for(int j = 1; j <= m; ++j) {
49             if(vis[i][j] <= Y && vis[i][j] - j + c <= X) {
50               //  printf("%d %d %d
", vis[i][j], i, j);
51                 ++ans;
52             }
53         }
54     }
55     printf("%d
", ans);
56     return 0;
57 }
View Code

 

以上是关于非原创codeforces 1063B Labyrinth 01bfs的主要内容,如果未能解决你的问题,请参考以下文章

非原创codeforces 1029F Multicolored Markers 贪心+构造

非原创codeforces 1070C Cloud Computing 线段树&树状数组

codeforces 1029E Tree with Small Distances思维+贪心 非原创

题解 CF1063B Labyrinth

极值问题CF1063B Labyrinth

CF1063B Labyrinth