[Codeforces Round #354 DIV2D (CF676D)] Theseus and labyrinth
来源:互联网 发布:zip mac怎么解压软件 编辑:程序博客网 时间:2024/05/29 13:06
题意
题解
拆点,每个格子拆成四种状态的点,然后
代码
/// by ztx#include <bits/stdc++.h>// 1 1 1 1// U D L R// 8 4 2 1#define U 8#define D 4#define L 2#define R 1#define maxn 1010LLstruct P { int x, y, t; } now;int vis[4][maxn][maxn];std::deque<P>q;char map[4][maxn][maxn];const int dx[4] = {-1, 1 , 0 , 0 };const int dy[4] = {0 , 0 , -1, 1 };char ch;inline void GetStatus(int x,int y) { ch = map[0][x][y]; if (ch == '*') map[0][x][y] = map[1][x][y] = map[2][x][y] = map[3][x][y] = 0; else if (ch == '+') map[0][x][y] = map[1][x][y] = map[2][x][y] = map[3][x][y] = 15; else if (ch == '-') map[0][x][y] = map[2][x][y] = 3, map[1][x][y] = map[3][x][y] = 12; else if (ch == '|') map[0][x][y] = map[2][x][y] = 12, map[1][x][y] = map[3][x][y] = 3; else if (ch == '^') map[0][x][y] = U, map[1][x][y] = R, map[2][x][y] = D, map[3][x][y] = L; else if (ch == '>') map[0][x][y] = R, map[1][x][y] = D, map[2][x][y] = L, map[3][x][y] = U; else if (ch == '<') map[0][x][y] = L, map[1][x][y] = U, map[2][x][y] = R, map[3][x][y] = D; else if (ch == 'v') map[0][x][y] = D, map[1][x][y] = L, map[2][x][y] = U, map[3][x][y] = R; else if (ch == 'L') map[0][x][y] = 15^L, map[1][x][y] = 15^U, map[2][x][y] = 15^R, map[3][x][y] = 15^D; else if (ch == 'R') map[0][x][y] = 15^R, map[1][x][y] = 15^D, map[2][x][y] = 15^L, map[3][x][y] = 15^U; else if (ch == 'U') map[0][x][y] = 15^U, map[1][x][y] = 15^R, map[2][x][y] = 15^D, map[3][x][y] = 15^L; else if (ch == 'D') map[0][x][y] = 15^D, map[1][x][y] = 15^L, map[2][x][y] = 15^U, map[3][x][y] = 15^R;}int main() { int n, m, i, j, t, tt, x, y, x0, y0; scanf("%d%d", &n, &m); for (i = 1; i <= n; i ++ ) scanf("%s", map[0][i]+1); scanf("%d%d%d%d", &x, &y, &x0, &y0); for (i = 1; i <= n; i ++ ) for (j = 1; j <= m; j ++ ) GetStatus(i,j); vis[0][x][y] = 1; q.clear(), q.push_back((P){x,y,0}); while (!q.empty()) { now = q.front(), q.pop_front(), t = now.t; if (now.x == x0 && now.y == y0) { printf("%d\n", vis[now.t][now.x][now.y]-1); goto END; } for (i = 0; i < 4; i ++ ) { x = now.x+dx[i], y = now.y+dy[i]; if (vis[t][x][y]) continue; if (i==0 && (((map[t][now.x][now.y]&U)==0) || ((map[t][x][y]&D)==0))) continue; if (i==1 && (((map[t][now.x][now.y]&D)==0) || ((map[t][x][y]&U)==0))) continue; if (i==2 && (((map[t][now.x][now.y]&L)==0) || ((map[t][x][y]&R)==0))) continue; if (i==3 && (((map[t][now.x][now.y]&R)==0) || ((map[t][x][y]&L)==0))) continue; vis[t][x][y] = vis[t][now.x][now.y]+1, q.push_back((P){x,y,t}); } t ++ , t %= 4; if (!vis[t][now.x][now.y]) vis[t][now.x][now.y] = vis[now.t][now.x][now.y]+1, q.push_back((P){now.x,now.y,t}); } puts("-1"); END:; getchar(),getchar(); return 0;}
0 0
- [Codeforces Round #354 DIV2D (CF676D)] Theseus and labyrinth
- Codeforces Round #354 (Div. 2)676D. Theseus and labyrinth
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth (BFS)
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth
- Codeforces Round #354 (Div. 2) D Theseus and labyrinth
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth(BFS)
- codeforces 354D. Theseus and labyrinth bfs
- Codeforces Round #354 (Div. 2) D.Theseus and labyrinth(BFS)
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth(bfs)
- Codeforces 676D Theseus and labyrinth
- 【Codeforces Round 354 (Div 2)D】【迷宫搜索BFS】Theseus and labyrinth 门门互达 可做旋转操作 最少步数起点到终点
- Codeforces Round #354 (Div. 2)-Theseus and labyrint
- Codeforces 676D Theseus and labyrinth 模拟+bfs
- Codeforces 676D Theseus and labyrinth(最短路)
- Codeforces 676D Theseus and labyrinth【模拟+Bfs】
- Codeforces 676D Theseus and labyrinth 模拟+bfs
- codeforces_676D. Theseus and labyrinth(bfs)
- 【25.93%】【676D】Theseus and labyrinth
- 华为机试在线训练-牛客网(8)句子逆序
- 算法之路二:刘汝佳算法竞赛入门经典 信息解码 UVA213
- 网络安全的专家—防火墙!!续
- Linux tomcat根据物理内存大小动态配置JVM内存
- Linux SPI总线和设备驱动架构之三:SPI控制器驱动
- [Codeforces Round #354 DIV2D (CF676D)] Theseus and labyrinth
- SqlMap用户手册
- PHP基础之数据类型、单双引号区别和定界符
- 短信验证码之签名和模板
- 猫哥带你去战斗——Java Web开发——网页篇[3]——继续基本标签
- 微信小程序之页面跳转、传参
- 连接oracle数据库超时引发的问题。
- eclipse环境搭建ssh(Struts2+Spring2.5+Hibernate3)框架小谈(下)
- Active的多种部署方式