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 |
求问各位好人,我是用bfs 加位运算做的,但是不知道为什么runtime error#include<iostream> using namespace std; int num; #define max 10000000 int b[16]={0xf888,0xf444,0xf222,0xf111,0x8f88,0x4f44,0x2f22,0x1f11, 0x88f8,0x44f4,0x22f2,0x11f1,0x888f,0x444f,0x222f,0x111f}; struct node { int data; int state; int step; }queue[max],t,d; void bfs() { int front=0; int rear=1; int i,j; int visit[max]={0}; queue[0].data=num; queue[0].step=0; queue[0].state=0; visit[num]=1; while(1) { t=queue[front++%max]; for(i=0;i<16;i++) { d.data=t.data^b[i]; d.step=t.step+1; if(!visit[d.data]) { visit[d.data]=1; d.state=t.state|(1<<i); queue[rear++%max]=d; if(d.data==0) { cout<<d.step<<endl; for(j=0;j<16;j++) { if(d.state&(1<<j)) cout<<j/4+1<<" "<<j%4+1<<endl; } return ; } } } } } int main() { num=0; int i; char ch; for(i=0;i<16;i++) { scanf("%c",&ch); if(ch=='-') num=num*2+0; else num=num*2+1; if(i%4==3)getchar(); } bfs(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator