Codeforces 877 D Olya and Energy Drinks
来源:互联网 发布:投影幕布 白墙 知乎 编辑:程序博客网 时间:2024/05/17 23:13
题目地址
题意:给你一个地图,‘.’是可以走的路。‘#’是不能走的地方,然后她每分钟能走1~k个格子,告诉你起点和终点,问你要多少分钟从起点到终点。
思路:就是简单的广搜,每次都要遍历下这个方向的1~k个格子,然后因为是广搜,之后到这个点的耗时要不是等于这个时间要不就更大。然后如果遇到了墙或者出去了就直接找过一个方向。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 1010#define M 2000010//双倍#define LL __int64#define inf 0x3f3f3f3f3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;const double eps = 0.001;char mapp[N][N];bool vis[N][N];int dir[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };int n, m, k;int sx, sy, ex, ey;struct node { int x, y; int len;}now;int bfs() { if (sx == ex&&sy == ey) { return 0; } queue<node> q; now.x = sx; now.y = sy; now.len = 0; q.push(now); memset(vis, 0, sizeof(vis)); vis[sx][sy] = 1; while (!q.empty()) { now = q.front(); q.pop(); int x, y, xx, yy, len; x = now.x; y = now.y; len = now.len; for (int i = 0; i < 4; i++) { for (int j = 1; j <= k; j++) { xx = x + dir[i][0] * j; yy = y + dir[i][1] * j; if (xx == ex&&yy == ey) { return len + 1; } if (xx < 1 || xx > n || yy < 1 || yy > m || mapp[xx][yy] == '#') { break; } if (vis[xx][yy] == 0) { vis[xx][yy] = 1; now.x = xx; now.y = yy; now.len = len + 1; q.push(now); } } } } return -1;}int main() { cin.sync_with_stdio(false); while (cin >> n >> m >> k) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> mapp[i][j]; } } cin >> sx >> sy >> ex >> ey; cout << bfs() << endl; } return 0;}
阅读全文
0 0
- Codeforces 877 D Olya and Energy Drinks
- Codeforces 877D Olya and Energy Drinks【思维优化Bfs】
- Codeforces 877 D. Olya and Energy Drinks (bfs)
- codeforces 877 problem D Olya and Energy Drinks 【bfs剪枝】
- Codeforces Round #877 (Div. 2) D. Olya and Energy Drinks
- [codeforces] 877D. Olya and Energy Drinks (BFS)
- cf 877D Olya and Energy Drinks
- Codeforces Round #442 (Div. 2) D. Olya and Energy Drinks
- Codeforces Round #442 (Div. 2) 877 D. Olya and Energy Drinks BFS
- Codeforces 877D. Olya and Energy Drinks BFS+并查集
- codeforces #442 div2 Olya and Energy Drinks
- Codeforces Round #442(Div.2)Problem D Olya and Energy Drinks(BFS)
- Codeforces Round #442 (Div. 2) D. Olya and Energy Drinks (bfs)
- Codeforces Round #442 (Div. 2)-广搜&剪枝&技巧&好题-D. Olya and Energy Drinks
- Codeforces Round #442 (Div. 2) Olya and Energy Drinks(搜索 bfs 套路题)
- CodeForces 305D Olya and Graph
- Codeforces Drinks
- CodeForces 200B Drinks
- PHP扩展pcntl(进程控制以及信号处理)中文文档
- 2.5、集
- json字符串转换为JSONObject和JSONArray
- Spring-MockMvc
- 10月25日 c语言 打印所有水仙花数
- Codeforces 877 D Olya and Energy Drinks
- 深入学习c#(2)
- java 中 new 关键字
- 关于android的一个全局异常捕获类
- java 异常捕捉 ( try catch finally )
- Phalcon报错Can't obtain model's source from models list:xxx
- Java 的发展史
- Docker容器介绍资料
- SylixOS USB Gadget层介绍