标签:des style blog http color io os ar java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1501 Accepted Submission(s): 802
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <vector> 6 #include <queue> 7 using namespace std; 8 9 #define N 55 10 11 char map[N][N]; 12 int n; 13 14 struct node{ 15 int x, y; 16 }a[N*N]; 17 18 19 main() 20 { 21 int i, j, k; 22 while(scanf("%d",&n)==1&&n){ 23 for(i=0;i<n;i++) scanf("%s",map[i]); 24 k=0; 25 for(i=0;i<n;i++){ 26 for(j=0;j<n;j++){ 27 if(map[i][j]==‘#‘){ 28 a[k].x=i;a[k].y=j;k++; 29 } 30 } 31 } 32 int ans=0, f; 33 for(i=0;i<k;i++){ 34 if(a[i].x==0||a[i].x==n-1||a[i].y==0||a[i].y==n-1) continue; 35 if(map[a[i].x][a[i].y+1]!=‘#‘||map[a[i].x][a[i].y-1]!=‘#‘||map[a[i].x+1][a[i].y]!=‘#‘||map[a[i].x-1][a[i].y]!=‘#‘) continue; 36 int len1, len2; 37 int xx=a[i].x-1, yy=a[i].y; 38 len1=len2=0;f=1; 39 while(map[xx][yy]==‘#‘){//up 40 len1++; 41 if(map[xx][yy-1]==‘#‘||map[xx][yy+1]==‘#‘){ 42 f=0;break; 43 } 44 xx--; 45 if(xx<0) break; 46 } 47 if(!f) continue; 48 xx=a[i].x+1; 49 while(map[xx][yy]==‘#‘){//down 50 len2++; 51 if(map[xx][yy-1]==‘#‘||map[xx][yy+1]==‘#‘){ 52 f=0;break; 53 } 54 xx++; 55 if(xx>=n) break; 56 } 57 if(!f) continue; 58 if(len1!=len2) continue; 59 len2=0; 60 xx=a[i].x;yy=a[i].y-1; 61 while(map[xx][yy]==‘#‘){//left 62 len2++; 63 if(map[xx-1][yy]==‘#‘||map[xx+1][yy]==‘#‘){ 64 f=0;break; 65 } 66 yy--; 67 if(yy<0) break; 68 } 69 if(!f) continue; 70 if(len1!=len2) continue; 71 len2=0; 72 yy=a[i].y+1; 73 while(map[xx][yy]==‘#‘){//right 74 len2++; 75 if(map[xx-1][yy]==‘#‘||map[xx+1][yy]==‘#‘){ 76 f=0;break; 77 } 78 yy++; 79 if(yy>=n) break; 80 } 81 if(!f) continue; 82 if(len1!=len2) continue; 83 ans++; 84 } 85 printf("%d\n",ans); 86 } 87 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/qq1012662902/p/4041520.html