HDU-2487
2015-07-27 18:42
260 查看
Ugly Windows
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1474 Accepted Submission(s): 588
[align=left]Problem Description[/align]
Sheryl works for a software company in the country of Brada. Her job is to develop a Windows operating system. People in Brada are incredibly conservative. They even never use graphical monitors! So Sheryl’s operating system has to run in text mode and windows in that system are formed by characters. Sheryl decides that every window has an ID which is a capital English letter (‘A’ to ‘Z’). Because every window had a unique ID, there can’t be more than 26 windows at the same time. And as you know, all windows are rectangular.
On the screen of that ugly Windows system, a window’s frame is formed by its ID letters. Fig-1 shows that there is only one window on the screen, and that window’s ID is ‘A’. Windows may overlap. Fig-2 shows the situation that window B is on the top of window A. And Fig-3 gives a more complicated overlapping. Of course, if some parts of a window are covered by other windows, you can’t see those parts on the screen.
.........................
....AAAAAAAAAAAAA........
....A...........A........
....A...........A........
....A...........A........
....AAAAAAAAAAAAA........
.........................
Fig-1
.........................
....AAAAAAAAAAAAA........
....A...........A........
....A.......BBBBBBBBBB...
....A.......B........B...
....AAAAAAAAB........B...
............BBBBBBBBBB...
.........................
Fig-2
..........................
....AAAAAAAAAAAAA.........
....A...........A.........
....A.......BBBBBBBBBB....
....A.......B........BCCC.
....AAAAAAAAB........B..C.
.......C....BBBBBBBBBB..C.
.......CCCCCCCCCCCCCCCCCC.
..........................
Fig-3
If a window has no parts covered by other windows, we call it a “top window” (The frame is also considered as a part of a window). Usually, the top windows are the windows that interact with user most frequently. Assigning top windows more CPU time and higher priority will result in better user experiences. Given the screen presented as Figs above, can you tell Sheryl which windows are top windows?
[align=left]Input[/align]
The input contains several test cases.
Each test case begins with two integers, n and m (1 <= n, m <= 100), indicating that the screen has n lines, and each line consists of m characters.
The following n lines describe the whole screen you see. Each line contains m characters. For characters which are not on any window frame, we just replace them with ‘.’ .
The input ends with a line of two zeros.
It is guaranteed that:
1) There is at least one window on the screen.
2) Any window’s frame is at least 3 characters wide and 3 characters high.
3) No part of any window is outside the screen.
[align=left]Output[/align]
For each test case, output the IDs of all top windows in a line without blanks and in alphabet order.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
B
AD
[align=left]Source[/align]
2008 Asia Regional Beijing
[align=left]Recommend[/align]
gaojie
/** 题意:给一个图,然后判断是哪一个图在上边,并且该框是>=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(); } }
相关文章推荐
- python数组过滤实现方法
- 内存管理
- LeetCode 235: Lowest Common Ancestor of a Binary Search Tree
- 枚举的使用
- Android - DownloadManager的使用
- SGU 390-Tickets(数位dp)
- Spring综合Struts2
- HTML—看完轻松入门
- 黑马程序员——10,线程
- HDU-2057 A+B Again
- 接收短信
- 图论加边算法--链式向前星
- AngularJS学习笔记(四)
- App Store 审核指南中文翻译
- iOS学习笔记--(c基础题9)
- leetcode oj 1
- 解决8080端口被占,Tomcat无法正常启动
- C/C++中的联合体union及CPU大小端判定
- 我的Android进阶之旅------>android:drawableLeft的用法
- Object-C 面向对象的三大特征