HDU-2487

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

2008 Asia Regional Beijing

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[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
char ch[maxn][maxn];
int alp[30];
struct Node
{
    int x;
    int y;
} node[maxn];
struct NN
{
    int x[5];
    int y[5];
    char c[10];
} no[30];
int n,m;
int check(int x,int y)
{
    if(x >=0 && x < n && y >= 0 && y < m && vis[x][y] == 0) return 1;
    return 0;
}
int bfs(int x,int y)
{
    queue<Node>que;
    Node tmp,now;
    vis[x][y] = 1;
    tmp.x = x;
    tmp.y = y;
    char c = ch[x][y];
    que.push(tmp);
    int sum = 1;
    while(!que.empty())
    {
        now = que.front();
        que.pop();
        for(int i=0; i<4; 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] = 1;
                que.push(tmp);
                sum++;
            }
        }
    }
    return sum;
}
int solve()
{
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            int num1 = 0;
            int num2 = 0;
            int num = 0;
            int res = 0;
            if(ch[i][j] != ‘.‘ && vis[i][j] == 0)
            {
                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 == 2*( num1 + num2 -2) && num1 >=3 && num2 >= 3 && num >= 8)
                {
                    int tt = ch[i][j] - ‘A‘;
                    alp[tt] = 1;
                    no[tt].x[0] = i;
                    no[tt].x[1] = i+ num1 -1;
                    no[tt].y[0] = j;
                    no[tt].y[1] = j + num2 -1;
                }
            }
        }
    }
    for(int i=0; i<26; i++)
    {
        if(alp[i] == 1)
            for(int j=0; j<26; j++)
            {
                if(alp[j] == 1 && no[i].x[0] < no[j].x[0] && no[i].x[1] > no[j].x[1] && no[i].y[0]< no[j].y[0] && no[i].y[1] > no[j].y[1])
                {
                    alp[i] = 0;
                   // break;
                }
            }
    }
    for(int i=0; i<26; 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 == 0 && m == 0) break;
        for(int i=0; i<n; i++)
        {

            scanf("%s",ch[i]);

        }
        memset(vis,0,sizeof(vis));
        memset(alp,0,sizeof(alp));
        solve();
    }
}
时间: 2024-10-24 11:14:59

HDU-2487的相关文章

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

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

POJ 3923 &amp;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 con

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

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

[hdu 2102]bfs+注意INF

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的--把INF改成INF+INF就过了. #include<bits/stdc++.h> using namespace std; bool vis[2][15][15]; char s[2][15][15]; const int INF=0x3f3f3f3f; const int fx[]={0,0,1,-1};

HDU 3555 Bomb (数位DP)

数位dp,主要用来解决统计满足某类特殊关系或有某些特点的区间内的数的个数,它是按位来进行计数统计的,可以保存子状态,速度较快.数位dp做多了后,套路基本上都差不多,关键把要保存的状态给抽象出来,保存下来. 简介: 顾名思义,所谓的数位DP就是按照数字的个,十,百,千--位数进行的DP.数位DP的题目有着非常明显的性质: 询问[l,r]的区间内,有多少的数字满足某个性质 做法根据前缀和的思想,求出[0,l-1]和[0,r]中满足性质的数的个数,然后相减即可. 算法核心: 关于数位DP,貌似写法还是

HDU 5917 Instability ramsey定理

http://acm.hdu.edu.cn/showproblem.php?pid=5917 即世界上任意6个人中,总有3个人相互认识,或互相皆不认识. 所以子集 >= 6的一定是合法的. 然后总的子集数目是2^n,减去不合法的,暴力枚举即可. 选了1个肯定不合法,2个也是,3个的话C(n, 3)枚举判断,C(n, 4), C(n, 5) #include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false) using name