Flip Game

http://poj.org/problem?id=1753

 #include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std; char s[][];
int a[][];
int deep,step,flag;
void inti(int row,int c)
{
a[row-][c]=!a[row-][c];
a[row][c+]=!a[row][c+];
a[row+][c]=!a[row+][c];
a[row][c-]=!a[row][c-];
a[row][c]=!a[row][c];
}
int check()
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
if(a[i][j]!=a[][]) return ;
}
}
return ;
}
void dfs(int row,int c,int deep)
{
if(deep==step)
{
flag=check();
return;
}
if(flag||row==) return;
inti(row,c);
if(c<)
dfs(row,c+,deep+);
else
dfs(row+,,deep+); inti(row,c);
if(c<)
dfs(row,c+,deep);
else
dfs(row+,,deep);
return ;
}
int main()
{
memset(a,,sizeof(a));
for(int i=; i<; i++)
{
scanf("%s",s[i]);
}
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(s[i][j]=='b')
a[i+][j+]=;
}
}
for(step=; step<=; step++)
{
dfs(,,);
if(flag)
{
printf("%d\n",step);
break;
}
}
if(!flag) printf("Impossible\n");
return ;
}
上一篇:NodeJs编译失败,npm install的时候出现python和node-gyp错误


下一篇:初探 Ext JS 6 (sencha touch/ext升级版)