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 |
为什么是runtime error?#include <iostream> #include <queue> #include <bitset> #include <cstdio> using namespace std; int a[4][4]; unsigned int flag[10000]; unsigned int step[10000]; unsigned int stat , temp; queue<int>q; int main() { int flip(int i,int j, int stat); stat<<=1; for(int i=0; i<4;i++,getchar()) for(int j=0;j<4;j++) {a[i][j]=getchar(); stat<<=1; a[i][j]=='b'?stat++:1; } q.push(stat); step[stat]=0; flag[stat]=1; while (q.size()) { stat=q.front(); for(int i=0;i<4;i++) for(int j=0;j<4;j++) { temp =flip(i,j,stat); if(temp==0x0000||temp==0xffff) {cout<<step[stat]+1<<endl; return 0 ;} else { q.push(temp); step[temp]=step[stat]+1; flag[temp]=1; } } q.pop(); } cout<<"impossible"<<endl; return 0; } int flip(int i,int j, int stat) { bitset<16>b(stat); b[i*4+j].flip(); i>0 && b[(i-1)*4+j].flip(); i<3 && b[(i+1)*4+j].flip(); j>0 && b[i*4+(j-1)].flip(); j<3 && b[i*4+(j+1)].flip(); return b.to_ulong(); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator