POJ 3923 HDU 2487 Ugly Windows 简单计算

Ugly Windows

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1670    Accepted Submission(s): 693

Problem Description
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?
 

 

Input
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.

 

 

Output
For each test case, output the IDs of all top windows in a line without blanks and in alphabet order.
 

 

Sample Input
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
 

 

Sample Output
B AD

 源代码:
 1 #include <iostream>
 2 #include <vector>
 3 using namespace std;
 4 const int big=10005;
 5 const int maxn=105;
 6 struct aaa {
 7     int x,y;
 8 };
 9 vector<aaa> c;
10 int n,m;
11 char a[maxn][maxn];
12 void make() {
13     char ch;
14     int i,j,minx,maxx,miny,maxy;
15     aaa node;
16     bool f;
17     for(ch='A';ch<='Z';ch++) {
18         c.clear();
19         for(i=1;i<=n;++i)
20             for(j=1;j<=m;++j)
21                 if(a[i][j]==ch) {
22                     node.x=i;node.y=j;
23                     c.push_back(node);
24                 }
25         if(c.size()==0) continue;
26         minx=big;miny=big;maxx=0;maxy=0;
27         for(i=0;i<(int)c.size();++i) {
28             if(c[i].x<minx) minx=c[i].x;
29             if(c[i].y<miny) miny=c[i].y;
30             if(c[i].x>maxx) maxx=c[i].x;
31             if(c[i].y>maxy) maxy=c[i].y;
32         }
33         if(maxx<minx+2) continue;
34         if(maxy<miny+2) continue;
35         if((int)c.size()!=(maxx-minx+maxy-miny)*2) continue;
36         f=true;
37         for(i=minx+1;i<maxx;++i)
38             for(j=miny+1;j<maxy;++j)
39                 if(isupper(a[i][j])) f=false;
40         if(f) cout<<ch;
41     }
42     cout<<endl;
43 }
44 int main() {
45     int i,j;
46     while(true) {
47         cin>>n>>m;
48         if(n+m==0) break;
49         for(i=1;i<=n;++i)
50             for(j=1;j<=m;++j)
51                 cin>>a[i][j];
52         make();
53     }
54     return 0;
55 }
View Code

 

posted @ 2017-11-03 01:43  lemonsbiscuit  阅读(119)  评论(0编辑  收藏  举报