uva10047(未AC)
Posted sanshi-2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva10047(未AC)相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h> using namespace std; struct Node{ int x, y, d, c; Node(int x = 0, int y = 0, int d = 0, int c = 0):x(x), y(y), d(d), c(c){} bool operator==(const Node& node)const{ return node.x == x && node.y == y && node.c == c; //direction is not needed. } }; const int maxn = 25 + 3; int R, C; char maze[maxn][maxn]; int vis[maxn][maxn][4][5]; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; int solve() { Node S, T; for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ char ch = maze[i][j]; if(ch == ‘.‘ || ch == ‘#‘) continue; if(ch == ‘S‘) S = {i, j, 0, 0}; else T = {i, j, 0, 0}; } } memset(vis, -1, sizeof(vis)); vis[S.x][S.y][S.d][S.c] = 0; queue<Node>q; q.push(S); while(!q.empty()){ Node u = q.front(); q.pop(); int x = u.x, y = u.y, d = u.d, c = u.c; if(T == u) return vis[x][y][d][c]; int v = vis[x][y][d][c] + 1; //go head int xx = x + dx[d], yy = y + dy[d]; if(xx >= 0 && xx < R && yy >= 0 && yy < C && maze[xx][yy] != ‘#‘ && vis[xx][yy][d][c] == -1){ vis[xx][yy][d][(c+1)%5] = v; q.push(Node(xx, yy, d, (c+1)%5)); } //turn, clockwise if(vis[x][y][(d+1)%4][c] == -1) {q.push(Node(x, y, (d+1)%4, c)); vis[x][y][(d+1)%4][c] = v;} if(vis[x][y][(d+3)%4][c] == -1) {q.push(Node(x, y, (d+3)%4, c)); vis[x][y][(d+3)%4][c] = v;} } return -1; } int main() { int cnt = 0; while(cin >> R >> C && R){ for(int i = 0; i < R; i++){ scanf("%s", maze[i]); } if(++cnt != 1) printf(" "); int ans = solve(); if(ans == -1) printf("Case #%d destination not reachable ", cnt); else printf("Case #%d minimum time = %d sec ", cnt, ans); } return 0; } /* 3 1 T . S */
以上是关于uva10047(未AC)的主要内容,如果未能解决你的问题,请参考以下文章
UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)