http://acm.hdu.edu.cn/showproblem.php?pid=4414
简单枚举
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>#define LL long long
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N=105;
string figure[N];
int n;
bool cross(int I,int J)
{int k1=0,k2=0,k3=0,k4=0;for(int j=J+1;j<n;++j){if(figure[I][j]=='#'){if(figure[I-1][j]=='o'&&figure[I+1][j]=='o')++k1;elsereturn false;}elsebreak;}if(k1==0)return false;for(int j=J-1;j>=0;--j){if(figure[I][j]=='#'){if(figure[I-1][j]=='o'&&figure[I+1][j]=='o')++k2;elsereturn false;}elsebreak;}if(k1!=k2)return false;for(int i=I+1;i<n;++i){if(figure[i][J]=='#'){if(figure[i][J+1]=='o'&&figure[i][J-1]=='o')++k3;elsereturn false;}elsebreak;}if(k1!=k3)return false;for(int i=I-1;i>=0;--i){if(figure[i][J]=='#'){if(figure[i][J+1]=='o'&&figure[i][J-1]=='o')++k4;elsereturn false;}elsebreak;}if(k1!=k4)return false;return true;}
int main()
{//freopen("data.txt","r",stdin);while(cin>>n){if(n==0)break;for(int i=0;i<n;++i)cin>>figure[i];int ans=0;for(int i=1;i<n-1;++i){for(int j=1;j<n-1;++j){if(figure[i][j]=='#'&&cross(i,j))++ans;}}cout<<ans<<endl;}return 0;
}