# 1815:画家问题 C

2018-02-05 10:39:12来源:oschina作者:BinksCN人点击

5
wwwww
wwwww
wwwww
wwwww
wwwww

15

——————————————————————分割线————————————————————

#include
int puzzle[20][20];
int press[20][20];
int n;
int ans;
int p=1;
bool guess()
{
int i,j;
for(i=2;i<=n;i++)
for(j=1;j<=n;j++)
press[i][j]=(puzzle[i-1][j]+press[i-1][j-1]+press[i-1][j]+press[i-1][j+1]+press[i-2][j])%2;
for(j=1;j<=n;j++)
if(press[n][j]!=(puzzle[n][j]+press[n][j-1]+press[n][j+1]+press[n-1][j])%2)
return true;
return false;
}
void solve()
{
for(c=1;c<=n;c++)
press[1][c]=0;
while(guess())
{
if(p==5000)
break;
p++;
press[1][1]++;
c=1;
while(press[1][c]>1)
{
press[1][c]=0;
c++;
press[1][c]++;
}
}
}
int main()
{
int i,j;
scanf("%d",&n);
for(i=0;i<=n;i++)
puzzle[i][0]=puzzle[i][n+1]=press[i][0]=press[i][n+1]=0;
for(j=0;j<=n+1;j++)
puzzle[0][j]=puzzle[n][j]=press[0][j]=press[n][j]=0;
char c[20];
int a=1;
for(i=1;i<=n;i++)
{
scanf("%s",&c);
for(j=0;j<=n-1;j++)
{
if(c[j]=='w')
{
puzzle[i][j+1]=1;
a=0;
}
else
puzzle[i][j+1]=0;
}
}
if(a==0)
solve();
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(press[i][j]==1)
ans++;
if(p==5000)
printf("inf/n");
else
printf("%d/n",ans);
return 0;
}