hdu2487(枚举)

Ugly Windows

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


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
       本题给定一个由字符串构成的图,要问其中是否有满足题目条件的窗口。
       本题数据比较小,不用多想直接模拟过程即可。抓住题目的条件进行优化。枚举字母,找出每个字符对应的矩形域,设左上角坐标为min_x,min_y,右下角坐标为max_x,max_y,该字符一共出现num次。一个符合条件的窗口满足下面左右条件:
                     1.max_x-min_x>=2且max_x-min_x>=2,保证尺寸大于等于3
                     2.num=(max_x-min_x+max_x-min_x)*2,此条件保证边框不被覆盖,1,2不能颠倒
                     3.在min_x<i<max_x且min_y<j<max_y范围内str[i][j]='.',保证中间不被小的窗口覆盖
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;

const int MAXN=100+10;
char str[MAXN][MAXN];
int n,m;

void Solve()
{
	int i,j,min_x,min_y,max_x,max_y,num;
	char ch;
	for(ch='A';ch<='Z';ch++)
	{
		min_x=110,min_y=110,max_x=-1,max_y=-1;
		num=0;
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				if(str[i][j]==ch)
				{
					if(i<min_y)min_y=i;
					if(i>max_y)max_y=i;
					if(j<min_x)min_x=j;
					if(j>max_x)max_x=j;
					num++;
				}
			}
		}
		if(min_x==110&&min_y==110&&max_x==-1&&max_y==-1)continue;//排除该字母不出现的情况
		if(!(max_x-min_x>=2&&max_y-min_y>=2))continue;//排除窗口的尺寸小于3
		if(num!=(max_x-min_x+max_y-min_y)*2)continue;//排除边框被盖住的情况

		bool flag=true;
		for(i=min_y+1;i<max_y;i++)//排除中间被覆盖的情况
		{
			for(j=min_x+1;j<max_x;j++)
			{
				if(str[i][j]!='.')
				{
					flag=false;
					break;
				}
			}
			if(!flag)break;
		}
		if(flag)printf("%c",ch);
	}
	printf("\n");
}


int main()
{
	int i;
//	freopen("in.txt","r",stdin);
	while(~scanf("%d%d",&n,&m))
	{
		if(0==n&&0==m)break;
		for(i=0;i<n;i++)
			scanf("%s",str[i]);
		Solve();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值