Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求路过的大牛们帮忙指出错误。。

Posted by 201321131067 at 2015-10-21 20:42:56 on Problem 1753
代码如下,思路简单,求指出错误


//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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator