Ugly Windows

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

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
 
Source
 
Recommend
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[] = {,,-,};
int dy[] = {,-,,};
char ch[maxn][maxn];
int alp[];
struct Node
{
int x;
int y;
} node[maxn];
struct NN
{
int x[];
int y[];
char c[];
} no[];
int n,m;
int check(int x,int y)
{
if(x >= && x < n && y >= && y < m && vis[x][y] == ) return ;
return ;
}
int bfs(int x,int y)
{
queue<Node>que;
Node tmp,now;
vis[x][y] = ;
tmp.x = x;
tmp.y = y;
char c = ch[x][y];
que.push(tmp);
int sum = ;
while(!que.empty())
{
now = que.front();
que.pop();
for(int i=; i<; 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] = ;
que.push(tmp);
sum++;
}
}
}
return sum;
}
int solve()
{
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
int num1 = ;
int num2 = ;
int num = ;
int res = ;
if(ch[i][j] != '.' && vis[i][j] == )
{
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 == *( num1 + num2 -) && num1 >= && num2 >= && num >= )
{
int tt = ch[i][j] - 'A';
alp[tt] = ;
no[tt].x[] = i;
no[tt].x[] = i+ num1 -;
no[tt].y[] = j;
no[tt].y[] = j + num2 -;
}
}
}
}
for(int i=; i<; i++)
{
if(alp[i] == )
for(int j=; j<; j++)
{
if(alp[j] == && no[i].x[] < no[j].x[] && no[i].x[] > no[j].x[] && no[i].y[]< no[j].y[] && no[i].y[] > no[j].y[])
{
alp[i] = ;
// break;
}
}
}
for(int i=; i<; 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 == && m == ) break;
for(int i=; i<n; i++)
{ scanf("%s",ch[i]); }
memset(vis,,sizeof(vis));
memset(alp,,sizeof(alp));
solve();
}
}

HDU-2487的更多相关文章

  1. HDU 2487 Ugly Windows

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

  2. HDU 2487 Ugly window

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

  3. POJ 3923 HDU 2487 Ugly Windows 简单计算

    Ugly Windows Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

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

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  10. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. 四道JavaScript面试题检测你的js基本功

    下面有四道简短的JavaScript小脚本,如果你能顺利预测脚本的运行结果,那么你的JavaScript基本功还是可以的.如果答错了,可以相应地去补一下缺漏的知识.反正也很简单,答错了只是说明你没了解 ...

  2. 使用Google的CDN JQuery库

    CDN的全称是Content Delivery Network,即内容分发网络.其目的是通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络"边缘" ...

  3. JQuery学习六

    <JQuery cookie>插件 cookie是保存在浏览器上的内容,用户在这次浏览页面的时候向cookie中保存文本内容.下次再访问页面的时侯就可以取出来上次保存的内容.这样可以得到上 ...

  4. C#学习之泛型准备

    想要把泛型搞明白,最好先弄明白下面的代码实例 本实例是建立了两个类,然后在类中可以添加任意类型的值,并且可以利用foreach语句读出 //第一个节点类,放在一个文件中 using System; u ...

  5. HDU1078记忆化搜索

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. FreeRTOS ------ 栈、堆、任务栈

    1.任务的栈资源(创建任务分配的资源,单位是4字节)来自 configTOTAL_HEAP_SIZE 定义的堆,如果任务栈总量超过 configTOTAL_HEAP_SIZE,任务创建失败: 2.如果 ...

  7. Activity-ListView

    在手机中经常有列表方式.如果Activity中只有唯一一个List(这也是通常的情况),可以继承ListActivity来实现.我们用两个例子来学习List. List例子一:利用Android自带的 ...

  8. Java中JAVA_HOME与CLASSPATH的解析(转)

    很多人在初学Java的时候经常会被书中介绍的一堆环境变量的设置搞得头昏脑胀,很多书中都会在初装JDK的时候让他大家设置JAVA_HOME环境变量,在开发程序的时候设置CLASSPATH环境变量,而很多 ...

  9. (转)如何在windows 2008 安装IIS

    首先声明本文转自http://www.pc6.com/infoview/Article_54712.html ,作者为清晨 转载的原因有两个,一是怕原文挂了,而是打算写一下在阿里云部署django的文 ...

  10. MS SQL 启用标识插入

    解决MSSQL字段为标识不能插入办法http://www.veryhuo.com 2009-09-21 Liehuo.Net 投递稿件 我有话说当 IDENTITY_INSERT 设置为 OFF 时, ...