Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
半年后回来 对比下代码风格In Reply To:poj 100题留念 弱弱贴下0ms的模拟队列的代码 Posted by:416221843 at 2017-02-20 21:39:11 想不到这是自己的poj的第100题..非常惭愧 现在才163题 又过了一遍专题 和当年不同的代码风格 忘记不可能的情况wa一发..大规模数据慎用string记录路径.. #include<cstring> #include<cstdio> #include<queue> #include<cmath> #include<string> #include<iostream> #include<map> #include<algorithm> using namespace std; int a, b, c, k, x, y, z, v[111][111][5]; char s[11][11] = { "","FILL(1)","FILL(2)","DROP(1)","DROP(2)","POUR(1,2)","POUR(2,1)" }; struct viia { int x, y; }; queue<viia>q; void out(int x, int y) { if (x + y == 0) return; out(v[x][y][1], v[x][y][2]); printf("%s\n", s[v[x][y][3]]); } int main() { scanf("%d%d%d", &a, &b, &c); viia d, e; d.x = d.y = 0; q.push(d); while (!q.empty()) { d = q.front(), q.pop(); if (d.x != a && !v[a][d.y][0]) { e.x = a, e.y = d.y, q.push(e); v[e.x][e.y][0] = v[d.x][d.y][0] + 1; v[e.x][e.y][1] = d.x, v[e.x][e.y][2] = d.y; v[e.x][e.y][3] = 1; if (e.x == c || e.y == c) { x = e.x, y = e.y; z = v[x][y][0]; break; } } if (d.y != b && !v[d.x][b][0]) { e.x = d.x, e.y = b, q.push(e); v[e.x][e.y][0] = v[d.x][d.y][0] + 1; v[e.x][e.y][1] = d.x, v[e.x][e.y][2] = d.y; v[e.x][e.y][3] = 2; if (e.x == c || e.y == c) { x = e.x, y = e.y; z = v[x][y][0]; break; } } if (d.x && !v[0][d.y][0]) { e.x = 0, e.y = d.y, q.push(e); v[e.x][e.y][0] = v[d.x][d.y][0] + 1; v[e.x][e.y][1] = d.x, v[e.x][e.y][2] = d.y; v[e.x][e.y][3] = 3; if (e.x == c || e.y == c) { x = e.x, y = e.y; z = v[x][y][0]; break; } } if (d.y && !v[d.x][0][0]) { e.x = d.x, e.y = 0, q.push(e); v[e.x][e.y][0] = v[d.x][d.y][0] + 1; v[e.x][e.y][1] = d.x, v[e.x][e.y][2] = d.y; v[e.x][e.y][3] = 4; if (e.x == c || e.y == c) { x = e.x, y = e.y; z = v[x][y][0]; break; } } k = min(d.x, b - d.y); if (!v[d.x - k][d.y + k][0]) { e.x = d.x - k, e.y = d.y + k, q.push(e); v[e.x][e.y][0] = v[d.x][d.y][0] + 1; v[e.x][e.y][1] = d.x, v[e.x][e.y][2] = d.y; v[e.x][e.y][3] = 5; if (e.x == c || e.y == c) { x = e.x, y = e.y; z = v[x][y][0]; break; } } k = min(a - d.x, d.y); if (!v[d.x + k][d.y - k][0]) { e.x = d.x + k, e.y = d.y - k, q.push(e); v[e.x][e.y][0] = v[d.x][d.y][0] + 1; v[e.x][e.y][1] = d.x, v[e.x][e.y][2] = d.y; v[e.x][e.y][3] = 6; if (e.x == c || e.y == c) { x = e.x, y = e.y; z = v[x][y][0]; break; } } } if (z)printf("%d\n", z), out(x, y); else puts("impossible"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator