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
 源代码:
 #include <iostream>
#include <vector>
using namespace std;
const int big=;
const int maxn=;
struct aaa {
int x,y;
};
vector<aaa> c;
int n,m;
char a[maxn][maxn];
void make() {
char ch;
int i,j,minx,maxx,miny,maxy;
aaa node;
bool f;
for(ch='A';ch<='Z';ch++) {
c.clear();
for(i=;i<=n;++i)
for(j=;j<=m;++j)
if(a[i][j]==ch) {
node.x=i;node.y=j;
c.push_back(node);
}
if(c.size()==) continue;
minx=big;miny=big;maxx=;maxy=;
for(i=;i<(int)c.size();++i) {
if(c[i].x<minx) minx=c[i].x;
if(c[i].y<miny) miny=c[i].y;
if(c[i].x>maxx) maxx=c[i].x;
if(c[i].y>maxy) maxy=c[i].y;
}
if(maxx<minx+) continue;
if(maxy<miny+) continue;
if((int)c.size()!=(maxx-minx+maxy-miny)*) continue;
f=true;
for(i=minx+;i<maxx;++i)
for(j=miny+;j<maxy;++j)
if(isupper(a[i][j])) f=false;
if(f) cout<<ch;
}
cout<<endl;
}
int main() {
int i,j;
while(true) {
cin>>n>>m;
if(n+m==) break;
for(i=;i<=n;++i)
for(j=;j<=m;++j)
cin>>a[i][j];
make();
}
return ;
}

POJ 3923 HDU 2487 Ugly Windows 简单计算的更多相关文章

  1. HDU 2487 Ugly Windows(暴力)(2008 Asia Regional Beijing)

    Description Sheryl works for a software company in the country of Brada. Her job is to develop a Win ...

  2. HDU 2487 Ugly Windows

    递归求解,代码不太好看,是2013年7月写的 代码: #include<stdio.h> #include<iostream> #include<string.h> ...

  3. HDU 2487 Ugly window

    这是切的很痛苦的一道题,自己测试了很多样例却终究不过,中间也做了诸多修改,后来无奈去网上看题解,发现遗漏了一种情况,就是两个窗口可能边框都能看见,但是一个嵌套在另一里面,而我判定是不是 “top wi ...

  4. 【HDOJ】2487 Ugly Windows

    暴力解. #include <cstdio> #include <cstring> #define MAXN 105 char map[MAXN][MAXN]; ]; int ...

  5. POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算

    求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...

  6. poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题

    poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ...

  7. POJ 2104&HDU 2665 Kth number(主席树入门+离散化)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 50247   Accepted: 17101 Ca ...

  8. POJ 3181 Dollar Dayz(全然背包+简单高精度加法)

    POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自 ...

  9. SDUT OJ 2616 简单计算

    简单计算 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 某天,XX 给YY 出了一道题,题目是: 给出n 个十进制的数,找出这n ...

随机推荐

  1. Msys2配置总结

    一.MSYS2的MirrorList配置 1.修改msys2安装目录下的/etc/pacman.d文件夹里面的3个mirrorlist.*文件 [mirrorlist.mingw32] #中国科学技术 ...

  2. Django+Nginx+uWSGI部署

    一.介绍 Django的部署可以有多种方式,采用nginx+uwsgi的方式是最常见的一种方式.在这种方式中,将nginx作为服务器前端,接收WEB的所有请求,统一管理请求.nginx把所有静态请求自 ...

  3. jQuery源码的一个坑

    纯吐槽 大半夜也真是够了,想学着jQ造个小轮子巩固下js,结果一开始就卡住了. 虽然之前也看过源码,但是主要是研究方法实现什么的,对于框架主函数和入口结构不怎么熟悉,于是想着一步一步调试看看. $(' ...

  4. JS框架设计读书笔记之-动画

    基础概念 CSS样式可分为两种,一种值接近无限的集合(color,width),一种值只有几种(display),可以进行计算的样式,产生了动画效果.\ 1. 动画的第一步是获得元素的精确样式值. 2 ...

  5. C#第二篇——关于C#中的正则表达式

    在C#中,正则表达式是用来进行查询在给出的一串字符中的某些字符或者数字的工具.与在办公软件中的查找功能相似,可以用精确查找也可以用模糊查找. 元字符: 元字符 说明 . 匹配除换行符以外的任意字符 \ ...

  6. C++有符号和无符号数的转换

    本文转自:http://www.94cto.com/index/Article/content/id/59973.html 1.引例: 今天在做了一道关于有符号数和无符号数相互转换及其左移/右移的问题 ...

  7. Problem C

    Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...

  8. AMD与commonJS

    CommonJS:它是一个同步的模式.但是这种模式并不适合于浏览器端,如果浏览器同步模式一个一个加载模块,那么打开将会变得非常的慢. AMD:它最大的特点就是可以异步的方式加载模块,具体的不同在于AM ...

  9. 【吐槽】关于256个 class可以覆盖一个id的问题

    还是说今天下午面试的事情,被面试官问了 40多分钟的问题,我觉得丫 一定是从哪个网站down了几份面试题,自个儿整合了一下,然后挨个问,刚开始感觉哟,不错哦,面试官懂的蛮多的. 然后问到某个问题之后, ...

  10. 机器学习数学|微积分梯度jensen不等式

    机器学习中的数学 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原创文章,如需转载请保留出处 本博客为七月在线邹博老师机器学习数学课程学习笔记 索引 微积分,梯度和Jensen不等式 Tay ...