HDUOJ----2487Ugly Windows
2014-04-04 14:46
399 查看
Ugly Windows
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1199 Accepted Submission(s): 467
[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
代码:
#include<iostream> #include<vector> using namespace std; const int maxn=1002; const int NN=102; char win[NN][NN]; typedef struct windows { int x,y; }ww; int n,m; void work() { int min_x,max_x,min_y,max_y,i,j; char ch; vector<ww>aa; ww temp; for(ch='A'; ch<='Z';ch++) { aa.clear(); min_x=min_y=maxn; max_x=max_y=0; for(i=0;i<n;i++) //---> y { for(j=0;j<m;j++) //--->x { if(ch==win[i][j]) //这样就存储了一个图 { temp.x=j+1; temp.y=i+1; aa.push_back(temp); } } } /*华丽丽的分割线对这个图进行分析找到他的四个极点*/ if(aa.size()==0) continue ; //说明没有这个windows for(i=0 ;i<aa.size();i++ ) { if(max_x<aa[i].x) max_x=aa[i].x; if(max_y<aa[i].y) max_y=aa[i].y; if(min_x>aa[i].x) min_x=aa[i].x; if(min_y>aa[i].y) min_y=aa[i].y; } if((max_x-min_x)<2||(max_y-min_y)<2||2*(max_x-min_x+max_y-min_y)!=aa.size()) continue; bool tag=false; for(i=min_y;i<(max_y-1);i++) { for(j=min_x;j<(max_x-1);j++) { if(win[i][j]>='A'&&win[i][j]<='Z') //判断是否在在框内有顶点框 { tag=true; goto loop; } } } loop: if(!tag) cout<<ch; } cout<<endl; } int main() { // int n,m; int i,j; while(cin>>n>>m,n+m) { for( i=0 ; i<n ; i++ ) { for( j=0 ; j<m ; j++) cin>>win[i][j]; } work(); } return 0; }
相关文章推荐
- jQuery.noConflict();
- Java中byte与16进制字符串的互相转换
- mysql在大数据量下,如何优化SQL语句?
- ajax进行邮箱是否已经注册验证出的错
- C# 观察者模式(委托的使用)
- tcpdump
- 读《春秋》有感之十一:晋悼公休养生息
- array2json() - Convert PHP arrays to JSON
- 没有规则可以创建/framework.jar需要的目标framework-res.apk 停止
- NDK: NativeActivity原理
- 计算年龄
- 获取屏幕宽高和密度
- linux 环境 mysql写入中文报错
- 遇到个鬼,在WIN08的DELL R710上安装CENTOS 63,无法格式化以前的硬盘分区,安装无法进行下去。
- 开关硬件去抖
- mysql如何设置主键和外键,实现级联更新、级联删除
- MySQL 添加约束,修改约束,删除约束
- 构建AIX环境下的RAC之--配置系统环境(1)
- POJ 3252 数位dp
- Spring Integration Webapp