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 |
请AC了的同学帮忙看看,为什么我这个为RE#include <iostream> #include <cstdio> using namespace std; char ch; bool v[66000]; typedef struct node { int i,j,f; }node; node p[66000]; int now; int main () { int i,j; int s,e,q[66000],d[66000],t,temp,u; bool flag; now = 0; for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { cin >> ch; if (ch == '+') { now = 2 * now + 1; } else { now = 2 * now; } } flag = false; memset (d,0,sizeof (d)); memset (v,false,sizeof (v)); p[now].f = -1; s = 0; e = 1; q[s] = now; while (s < e) { t = q[s++]; u = t; if (v[t] == false) { v[t] = true; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { t = u; //将第i行取反 temp = 1; temp <<= ((3 - i) * 4 + 3); t = t ^ temp; temp = 1; temp <<= ((3 - i) * 4 + 2); t = t ^ temp; temp = 1; temp <<= ((3 - i) * 4 + 1); t = t ^ temp; temp = 1; temp <<= ((3 - i) * 4); t = t ^ temp; //将第i列取反 temp = 1; temp <<= (15 - j); t = t ^ temp; temp = 1; temp <<= (11 - j); t = t ^ temp; temp = 1; temp <<= (7 - j); t = t ^ temp; temp = 1; temp <<= (3 - j); t = t ^ temp; //将(i,j)位置处再次取反,因为在前面已经取反了两次,所以要再次取反 temp = 1; temp <<= ((3 - i) * 4 + (3 - j)); t = t ^ temp; if (t == 0) { flag = true; p[t].f = u; p[t].i = i + 1; p[t].j = j + 1; d[t] = d[u] + 1; break; } if (v[t] == false) { q[e++] = t; d[t] = d[u] + 1; p[t].f = u; p[t].i = i + 1; p[t].j = j + 1; } } if (flag) break; } if (flag) break; } } if (flag) { cout << d[t] << endl; while (t != now) { cout << p[t].i << " " << p[t].j << endl; t = p[t].f; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator