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 |
为什么wa啊?????#include <iostream> #include <stdio.h> using namespace std; int i,j,c[4][4],fe[4][4],temp; long count,minc; char ch; bool r; void search() { int i,j,t; bool right; count=0; for(i=0;i<4;i++) for(j=0;j<4;j++) if (c[i][j]) { count++; if (fe[i][j]) fe[i][j]=0; else fe[i][j]=1; if (i>0) if (fe[i-1][j]) fe[i-1][j]=0; else fe[i-1][j]=1; if (i<3) if (fe[i+1][j]) fe[i+1][j]=0; else fe[i+1][j]=1; if (j>0) if (fe[i][j-1]) fe[i][j-1]=0; else fe[i][j-1]=1; if (j<3) if (fe[i][j+1]) fe[i][j+1]=0; else fe[i][j+1]=1; } t=fe[0][0];right=true; for(i=0;i<4;i++) { if (!right) break; for(j=0;j<4;j++) if (fe[i][j]!=t) { right=false; break; } } if (right) if (minc>count) minc=count; } int main() { for(i=0;i<4;i++) { for(j=0;j<4;j++) { cin>>ch; if (ch=='b') fe[i][j]=0; else fe[i][j]=1; } getchar(); } r=true;temp=fe[0][0]; for(i=0;i<4;i++) { if (!r) break; for(j=0;j<4;j++) if (fe[i][j]!=temp) { r=false; break; } } minc=65537; for(c[0][0]=0;c[0][0]<=1;c[0][0]++) for(c[0][1]=0;c[0][1]<=1;c[0][1]++) for(c[0][2]=0;c[0][2]<=1;c[0][2]++) for(c[0][3]=0;c[0][3]<=1;c[0][3]++) for(c[1][0]=0;c[1][0]<=1;c[1][0]++) for(c[1][1]=0;c[1][1]<=1;c[1][1]++) for(c[1][2]=0;c[1][2]<=1;c[1][2]++) for(c[1][3]=0;c[1][3]<=1;c[1][3]++) for(c[2][0]=0;c[2][0]<=1;c[2][0]++) for(c[2][1]=0;c[2][1]<=1;c[2][1]++) for(c[2][2]=0;c[2][2]<=1;c[2][2]++) for(c[2][3]=0;c[2][3]<=1;c[2][3]++) for(c[3][0]=0;c[3][0]<=1;c[3][0]++) for(c[3][1]=0;c[3][1]<=1;c[3][1]++) for(c[3][2]=0;c[3][2]<=1;c[3][2]++) for(c[3][3]=0;c[3][3]<=1;c[3][3]++) search(); if (r) cout<<0<<endl; else if (minc==65537) cout<<"Impossible"<<endl; else cout<<minc<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator