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 |
求路过的大牛们帮忙指出错误。。代码如下,思路简单,求指出错误 //1753 Flip Game #include<stdio.h> #include<string.h> bool s[25];//将16枚棋子存在一维数组 int min=0x7f7f7f7f,t=0;//t为翻动次数 bool All(){//判断棋子是否均为同一色 for(int i=1;i<16;i++){ if(s[i]!=s[i+1]) return false; } return true; } void qufan(int i){//翻第i歌棋子 s[i]=!s[i]; if(i-4>0) s[i-4]=!s[i-4]; if(i-1>0) s[i-1]=!s[i-1]; if(i+1<=16) s[i+1]=!s[i+1]; if(i+4<=16) s[i+4]=!s[i+4]; } void f(int i){//dfs递归 if(i>16) return; if(All()) min=min>t?t:min; f(i+1); qufan(i); t++; f(i+1); qufan(i); t--; } int main(){ memset(s,false,sizeof(s)); char temp; for(int i=1;i<=16;i++){//读数据 while(scanf("%c",&temp)&&temp=='\n'); if(temp=='b') s[i]=true; } f(1); if(min==0x7f7f7f7f) printf("Impossible\n"); else printf("%d\n",min); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator