基德KID.1412 发表于 2013-2-4 23:49:39

HDU 2579 Dating with girls(2)

KIDx 的解题报告
题意很简单:http://acm.hdu.edu.cn/showproblem.php?pid=2579

http://dl.iteye.com/upload/attachment/598885/2b8f8b61-d291-302e-84dc-1cc422951ab9.png#include <iostream>#include <queue>using namespace std;#define inf 0x3fffffff#define M 105int r, c, mod, step;//step加维枚举余数所有状态int x_move = {-1, 0, 1, 0};int y_move = {0, 1, 0, -1};char map;struct pos{int x, y, z;};void bfs (){pos ft, tp;int i, j, k;for (i = 0; i < r; i++){for (j = 0; j < c; j++){for (k = 0; k < 11; k++)step = inf;    //初始化if (map == 'Y')//起点ft.x = i, ft.y = j;}}ft.z = 0;step = 0;queue<pos> q;q.push (ft);while (!q.empty()){ft = q.front();q.pop();if (map == 'G')//终点{printf ("%d\n", step);return ;}for (i = 0; i < 4; i++){tp.x = ft.x + x_move;tp.y = ft.y + y_move;tp.z = (ft.z+1) % mod;if (tp.x < 0 || tp.y < 0 || tp.x >= r || tp.y >= c)continue;if (map == '#' && tp.z > 0)//余数是0才可以走到#continue;if (step <= step + 1)continue;//走过的状态就不用走了step = step + 1;q.push (tp);}}puts ("Please give me another chance!");}int main(){int t, i;scanf ("%d", &t);while (t--){scanf ("%d%d%d", &r, &c, &mod);for (i = 0; i < r; i++)scanf ("%s", map);bfs();}return 0;}
页: [1]
查看完整版本: HDU 2579 Dating with girls(2)