标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1474 Accepted Submission(s): 588
9 26
..........................
....AAAAAAAAAAAAA.........
....A...........A.........
....A.......BBBBBBBBBB....
....A.......B........BCCC.
....AAAAAAAAB........B..C.
.......C....BBBBBBBBBB..C.
.......CCCCCCCCCCCCCCCCCC.
..........................
7 25
.........................
....DDDDDDDDDDDDD........
....D...........D........
....D...........D........
....D...........D..AAA...
....DDDDDDDDDDDDD..A.A...
...................AAA...
0 0
/** 题意:给一个图,然后判断是哪一个图在上边,并且该框是>=3*3 做法:模拟 **/ #include <iostream> #include <stdio.h> #include <string.h> #include <cmath> #include <algorithm> #include <queue> #define maxn 110 using namespace std; int vis[maxn][maxn]; int dx[4] = {0,0,-1,1}; int dy[4] = {1,-1,0,0}; char ch[maxn][maxn]; int alp[30]; struct Node { int x; int y; } node[maxn]; struct NN { int x[5]; int y[5]; char c[10]; } no[30]; int n,m; int check(int x,int y) { if(x >=0 && x < n && y >= 0 && y < m && vis[x][y] == 0) return 1; return 0; } int bfs(int x,int y) { queue<Node>que; Node tmp,now; vis[x][y] = 1; tmp.x = x; tmp.y = y; char c = ch[x][y]; que.push(tmp); int sum = 1; while(!que.empty()) { now = que.front(); que.pop(); for(int i=0; i<4; i++) { tmp.x = now.x + dx[i]; tmp.y = now.y + dy[i]; if(check(tmp.x,tmp.y) && ch[tmp.x][tmp.y] == c) { vis[tmp.x][tmp.y] = 1; que.push(tmp); sum++; } } } return sum; } int solve() { for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { int num1 = 0; int num2 = 0; int num = 0; int res = 0; if(ch[i][j] != ‘.‘ && vis[i][j] == 0) { char c = ch[i][j]; for(int ii = i; ii<n; ii++) { if(ch[ii][j] == c) num1++; else break; } for(int jj= j; jj<m; jj++) { if(ch[i][jj] == c) num2++; else break; } num = bfs(i,j); if(num == 2*( num1 + num2 -2) && num1 >=3 && num2 >= 3 && num >= 8) { int tt = ch[i][j] - ‘A‘; alp[tt] = 1; no[tt].x[0] = i; no[tt].x[1] = i+ num1 -1; no[tt].y[0] = j; no[tt].y[1] = j + num2 -1; } } } } for(int i=0; i<26; i++) { if(alp[i] == 1) for(int j=0; j<26; j++) { if(alp[j] == 1 && no[i].x[0] < no[j].x[0] && no[i].x[1] > no[j].x[1] && no[i].y[0]< no[j].y[0] && no[i].y[1] > no[j].y[1]) { alp[i] = 0; // break; } } } for(int i=0; i<26; i++) { if(alp[i]) { printf("%c",i+‘A‘); } } printf("\n"); } int main() { // freopen("in.txt","r",stdin); while(~scanf("%d %d",&n,&m)) { if(n == 0 && m == 0) break; for(int i=0; i<n; i++) { scanf("%s",ch[i]); } memset(vis,0,sizeof(vis)); memset(alp,0,sizeof(alp)); solve(); } }
标签:
原文地址:http://www.cnblogs.com/chenyang920/p/4680939.html