直接搜尋‘o’周圍有沒有'.'有的話Can kill in one move!!!,
沒有就Can not kill in one move!!!。
水題。。。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char a[15][15];int vis[15][15];int fx[4][2]={{1,0},{-1,0},{0,1},{0,-1}};int dfs(int y,int x){vis[y][x]=1;int flag=0;for(int i=0;i<4;++i){int ty=y+fx[i][1];int tx=x+fx[i][0];if(vis[ty][tx])continue;if(a[ty][tx]=='.'){flag++;vis[ty][tx]=1;}else if(a[ty][tx]=='o')flag+=dfs(ty,tx);}//cout<<flag<<" "<<y<<" "<<x<<endl;return flag;}int main(){int n;cin>>n;int ca=1;while(n--){ int flag=0; for(int i=0;i<=n+1;++i) for(int j=0;j<=n+1;++j) a[i][j]='1'; for(int i=1;i<=9;++i) for(int j=1;j<=9;++j) cin>>a[i][j]; for(int i=1;i<=9;++i) for(int j=1;j<=9;++j) if(a[i][j]=='o') { //cout<<"he"; memset(vis,0,sizeof(vis)); if(dfs(i,j)<=1) flag=1; }cout<<"Case #"<<ca++<<": ";if(flag)cout<<"Can kill in one move!!!"<<endl;elsecout<<"Can not kill in one move!!!"<<endl; }}