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. LOJ6388:[THUPC2018]赛艇——题解

    https://loj.ac/problem/6388 如果你做过BZOJ5217:[Lydsy2017省队十连测]航海舰队的话,那么恭喜你,这道题就是大水题. 如果你做过BZOJ4259:残缺的字符 ...

  2. BZOJ4896 [Thu Summer Camp2016]补退选 【trie树】

    题目链接 BZOJ4896 题解 \(thu\)怎么那么喜欢出\(trie\)树的题... 我们当然可以按题意模拟建\(trie\) 询问的时候,由于存在删除操作,不满足单调性,不能直接二分答案 我们 ...

  3. 让IE6也支持position:fixed

    众所周知IE6不支持position:fixed,这个bug与IE6的双倍margin和不支持PNG透明等bug一样臭名昭著.前些天遇到了这个问题.当时就简单的无视了IE6,但是对于大项目或商业网站, ...

  4. httpClient需要的jar包

  5. Basic Data Structure HDU - 5929 (这个模拟我要报警了)

    Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operati ...

  6. poj2060——Taxi Cab Scheme(最小路径覆盖)

    Description Running a taxi station is not all that simple. Apart from the obvious demand for a centr ...

  7. 使用 Rational AppScan 保证 Web 应用的安全性,第 2 部分: 使用 Rational AppScan 应对 Web 应用攻击

    1 当前 Web 安全现状 互联网的发展历史也可以说是攻击与防护不断交织发展的过程.目前,全球因特网用户已达 13.5 亿,用户利用网络进行购物.银行转账支付和各种软件下载,企业用户更是依赖于互联网构 ...

  8. [LeetCode] 大数问题,相加和相乘,题 Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. UVA 1635 Irrelevant Elements

    https://vjudge.net/problem/UVA-1635 题意:n个数,每相邻两个求和,最后变成1个数,问这个数除m的余数与第几个数无关 n个数使用次数分别为C(n-1,i) i∈[0, ...

  10. mvc Dapper_Report_Down_ExcelFile

    一.基于Aspose.Cells.Dapper导出Excel Dapper的Query返回要不是对象的IEnumerable,要不是Dynamic的IEnumerable,都不适合不用反射就能够动态获 ...