就是題目長... 只要構好圖就可以了。
1:each block is a square measuring 2520 rels per side 。
2:The speed limit between two adjacent intersections is always constant, and may range from 1 to 9 rels per blip
每條邊的邊長都是2520,速度1-9. 所以按time = 2520 / speed 構圖。
00447988 |
2010-07-05 21:03:02 |
Accepted |
1012 |
15 MS |
1180 KB |
Visual C++ |
Slave_wc |
#include <iostream><br />#include <cstring><br />#include <queue><br />using namespace std;<br />#define MAXN 500<br />const int slave = 2520;<br />int map[MAXN][MAXN];<br />int dis[MAXN];<br />bool hash[MAXN];<br />struct Dij<br />{<br /> int id;<br /> int dis;<br /> bool friend operator < (const Dij a, const Dij b)<br /> {<br /> return a.dis > b.dis;<br /> }<br />};<br />Dij now, next;<br />int Bfs(int st, int ed, int n)<br />{<br /> memset(hash, false, sizeof(hash));<br /> memset(dis, 0x7f, sizeof(dis));<br /> priority_queue<Dij> Q;<br /> now.id = st;<br /> now.dis = 0;<br /> dis[st] = 0;<br /> Q.push(now);<br /> <br /> while (!Q.empty())<br /> {<br /> now = Q.top();<br /> Q.pop();<br /> <br /> if (hash[now.id])<br /> {<br /> continue;<br /> }<br /> if (now.id == ed)<br /> {<br /> return now.dis;<br /> }<br /> hash[now.id] = true;<br /> <br /> for (int j = 1; j <= n; j++)<br /> {<br /> if (!hash[j] && dis[j] > dis[now.id] + map[now.id][j])<br /> {<br /> dis[j] = dis[now.id] + map[now.id][j];<br /> next.id = j;<br /> next.dis = dis[j];<br /> Q.push(next);<br /> }<br /> }<br /> }<br /> return -1;<br />}<br />int main()<br />{<br /> int n, m, i, j, a, r, t;<br /> char str[10];<br /> <br /> while (scanf("%d %d", &n, &m) != EOF)<br /> {<br /> if (n == 0 && m == 0)<br /> {<br /> break;<br /> }<br /> r = 1;<br /> memset(map, 0x7f, sizeof(map));<br /> for (i = 1; i <= 2 * n + 1; i++)<br /> {<br /> if (i & 1)<br /> {<br /> for (j = 1; j <= m; j++)<br /> {<br /> scanf("%d %s", &a, str);<br /> if (a == 0)<br /> {<br /> continue;<br /> }<br /> int left = (r - 1) * (m + 1) + j;<br /> int right = left + 1;<br /> if (str[0] == '*')<br /> {<br /> t = slave / a;<br /> map[left][right] = t;<br /> map[right][left] = t;<br /> }<br /> else if (str[0] == '>')<br /> {<br /> t = slave / a;<br /> map[left][right] = t; <br /> }<br /> else if (str[0] == '<')<br /> {<br /> t = slave / a;<br /> map[right][left] = t;<br /> }<br /> }<br /> r++;<br /> }<br /> else<br /> {<br /> for (j = 1; j <= m + 1; j++)<br /> {<br /> scanf("%d %s", &a, str);<br /> if (a == 0)<br /> {<br /> continue;<br /> }<br /> int down = (r - 1) * (m + 1) + j;<br /> int up = down - (m + 1);<br /> if (str[0] == '*')<br /> {<br /> t = slave / a;<br /> map[up][down] = t;<br /> map[down][up] = t;<br /> }<br /> else if (str[0] == '^')<br /> {<br /> t = slave / a;<br /> map[down][up] = t; <br /> }<br /> else if (str[0] == 'v')<br /> {<br /> t = slave / a;<br /> map[up][down] = t;<br /> }<br /> }<br /> }<br /> }<br /> int st = 1;<br /> int ed = (n + 1) * (m + 1);<br /> int ans = Bfs(st, ed, ed);<br /> if (ans != -1)<br /> {<br /> printf("%d blips/n", ans);<br /> }<br /> else<br /> {<br /> puts("Holiday");<br /> }<br /> }<br /> return 0;<br />}<br />