POJ 3923 & HDU 2487 Ugly Windows(模拟)

题目链接:

PKU:http://poj.org/problem?

id=3923

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2487

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

Beijing 2008

PS:注意:

7 25

...BBBBBBBBBBBBBBB.......

...BDDDDDDDDDDDDDB.......

...BDAAAAAAAAAAADB.......

...BDA.........ADB.......

...BDAAAAAAAAAAADB.......

...BDDDDDDDDDDDDDB.......

...BBBBBBBBBBBBBBB.......

6 6

AAABBB

A.AB.B

AAABBB

CCCDDD

C.CD.D

CCCDDD

代码例如以下:

#include<cstdio>
#include<cstring>
const int maxn = 217;
char mp[maxn][maxn];
int vis[maxn];
int n,m;
int ok(int a,int b)
{
    int i, j;
    for(i = b; i <= m; i++)
    {
        if(mp[a][i]!=mp[a][b])
            break;
    }
    i--;
    for(j = a+1; j <= n; j++) //行
    {
        for(int k = b; k <= i; k++)//列
        {
            if(k==b||k==i)//边缘不同样
            {
                if(mp[j][k]!=mp[a][b])
                    return 0;
            }
            else if(mp[j][k]!=‘.‘)//底边
            {
                for(int l = b; l <= i; l++)
                {
                    if(mp[j][l]!=mp[a][b])
                        return 0;
                }
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int i,j;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0 && m == 0)
            break;
        memset(vis,0,sizeof vis);
        for(int i = 0; i < n; i++)
        {
            scanf("%s",mp[i]);
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(mp[i][j]!=‘.‘&&vis[mp[i][j]-‘A‘]==0)
                {
                    vis[mp[i][j]-‘A‘]=1;
                    if(ok(i,j))
                        vis[mp[i][j]-‘A‘]=2;
                }
            }
        }
        int flag=1;
        for(int i = 0; i < 26; i++)
        {
            if(vis[i] == 2)
            {
                if(flag)
                    printf("%c",i+‘A‘);
                else
                    printf(" %c",i+‘A‘);
            }
        }
        puts("");
    }

}
时间: 2024-10-01 03:32:27

POJ 3923 &amp; HDU 2487 Ugly Windows(模拟)的相关文章

POJ 3923 &amp; HDU 2487 Ugly Windows(模拟)

题目链接: PKU:http://poj.org/problem?id=3923 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2487 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 cons

hdu 2487 Ugly Windows 模拟

#include <cstdio> #include <iostream> #include <cstring> #include <vector> using namespace std; char map[110][110]; int n,m; #define inf 100000 struct node { int x,y; }; vector <node> nn; int main() { while(1) { int i,j,k; sc

HDU 2487 Ugly Windows

欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Ugly Windows Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1481    Accepted Submission(s): 591 Problem Description Sheryl works for a software company in the c

【HDOJ】2487 Ugly Windows

暴力解. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 105 5 6 char map[MAXN][MAXN]; 7 char visit[27]; 8 int n, m; 9 10 bool check(char c) { 11 int i, j; 12 int x1=MAXN, y1=MAXN, x2=-1, y2=-1; 13 14 for (i=0; i<n; ++i) { 15 for (j=0

Ugly Windows

poj3923:http://poj.org/problem?id=3923 题意:给出两个整数n.m表示屏幕的长宽.屏幕上有一些窗口,每个窗口都是矩形的,窗口的边框用同一个大写字母来表示,不同的窗口的大写字母必定不同. 由于窗口的重叠,有些窗口的有些部分被其他窗口覆盖.但是,肯定有一些窗口在最顶端,不被其他任何窗口覆盖.我们称这些窗口为“顶端窗口”.你的任务就是找出所有的顶端窗口. 题解:简单的模拟.结果我错了很多次啊.首先,没有考虑到边框的内部一定要是'.',然后是最坑就是每个窗口的高度和宽

hdu 3125 Slash(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3125 Problem Description The American English slash (/) is a punctuation mark. In the early modern period, in the Fraktur script, which was widespread through Europe in the Middle Ages, one slash(/) repr

POJ 1068--Parencodings--括号逆匹配(模拟)

Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19655   Accepted: 11870 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn

hdu 1175 连连看(模拟循环队列)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18149    Accepted Submission(s): 4741 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通过一条线连起来(这条

HDU 4608 I-number--简单模拟

I-number Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The I-number of x is defined to be an integer y, which satisfied the the conditions below: 1.  y>x; 2.  the sum of each digit of y(under base 10) is the multiple of 10; 3.  among all