hdu 4414 暴力枚举
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; const int maxe = 50000; const int maxn = 65; const int INF = 0x3f3f3f; char G[maxn][maxn]; bool vis[maxn][maxn]; int ans; int N; int main() { //freopen("E:\\acm\\input.txt","r",stdin); while(scanf("%d",&N) && N){ for(int i=0;i<N;i++) scanf("%s",G[i]); memset(vis,0,sizeof(vis)); ans = 0; for(int i=1;i<N-1;i++) for(int j=1;j<N-1;j++){ if(G[i][j] == 'o') continue; if(vis[i][j]) continue; for(int len=1;len<=N;len++){ if( len > 1 &&(i-len<0||G[i-len][j]=='o') &&(i+len>=N|| G[i+len][j]=='o')&& (j+len>=N||G[i][j+len]=='o') &&(G[i][j-len]=='o'||j-len<0) ){ ans ++ ; break; } if(i-len<0 || i+len>=N || j-len<0 || j+len>=N) break; if(G[i-len][j]=='o') break; if(G[i+len][j]=='o') break; if(G[i][j-len]=='o') break; if(G[i][j+len]=='o') break; if(G[i-len][j-1]=='#' || G[i-len][j+1]=='#') break; if(G[i+len][j-1]=='#' || G[i+len][j+1]=='#') break; if(G[i-1][j-len]=='#' || G[i+1][j-len]=='#') break; if(G[i-1][j+len]=='#' || G[i+1][j+len]=='#') break; vis[i-len][j] = vis[i+len][j] = true; vis[i][j-len] = vis[i][j+len] = true; } } printf("%d\n",ans); } }