HDU 2487 Ugly Windows

Source: Internet
Author: User

Welcome to the--bestcoder Anniversary (High quality topic + multiple Rewards)
Ugly WindowsTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1481 Accepted Submission (s): 591


Problem Descriptionsheryl works for a software company in the country of Brada. Her job was to develop a Windows operating system. People in Brada is incredibly conservative. They even never use graphical monitors! So Sheryl's operating system has the to run in text mode and Windows on that system is formed by characters. Sheryl decides that every window have an ID which are a capital 中文版 (' a ' to ' Z '). Because every window had a unique ID, there can ' t be more than-windows at the same time. And as you know, all windows is rectangular.

On the screens of that ugly Windows system, a window's frame is formed by its ID letters. Fig-1 shows that there was only one window in the screen, and that window's ID is ' A '. Windows may overlap. Fig-2 shows the situation that Windows B is on the top of window A. And Fig-3 gives a more complicated overlapping. Of course, if some parts of a window is 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 is the Windows interact with the user most frequently. Assigning top Windows more CPU time and higher the priority would result in better user experiences. Given the screen presented as Figs above, can-tell Sheryl which Windows is top Windows?
Inputthe input contains several test cases.

Each test case is begins with a integers, N and m (1 <= N, M <=), indicating that the screens has n lines, and EAC H line consists of M characters.

The following n lines describe the whole screen you see. Each line contains m characters. For characters which is not on any window frame, we just replace them with '. '.

The input ends with a line of zeros.

It's Guaranteed that:

1) There is at least one window in the screen.
2) Any window ' s frame are at least 3 characters wide and 3 characters high.
3) No part of any window was outside the screen.


Outputfor each test case, output the IDs of any top windows in a line without blanks and in Alphabet order.
Sample Input9 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 Outputbad
Source-Asia Regional Beijing
Recommendgaojie | We have carefully selected several similar problems for you:2485 2489 2488 2490 2493
#include <stdio.h>//the only hole in the case is if a large window is still contained inside the small window, then the inside of the window output, and the outside windows do not count#include<string.h>#include<iostream>#include<algorithm>using namespacestd;Charstr[ $][ $];Charans[ $];intCNT;BOOLvis[ -];BOOLcmpCharT1,CharT2) {   returnt1<T2;}intX2,y2;intJudge1 (intNintMintXintYCharc) {     inti=x,j=y;  while(i<=n&&str[i][j]==c) i++; i--; inttemp1=i-x;  while(j<=m&&str[i][j]==c) j + +; j--; inttemp2=j-y; X2=i; Y2=J;  while(i>=1&AMP;&AMP;STR[I][J]==C) i--; i++;  while(j>=1&AMP;&AMP;STR[I][J]==C) j--; J + +; if(i==x&&j==y&&temp1>=2&&temp2>=2)        return 1; return 0;}intJudge2 (intX1,inty1) {    for(inti=x1+1; i<x2;i++){     for(intj=y1+1; j<y2;j++)        if(str[i][j]!='.')        return 0; }   return 1;}intMain () {intx, y;  while(SCANF ("%d%d", &x,&y)! =EOF) {        if(x==0&&y==0)             Break; memset (ans,0,sizeof(ans)); memset (str,0,sizeof(str)); memset (Vis,false,sizeof(VIS));        GetChar ();  for(intI=1; i<=x;i++){             for(intj=1; j<=y;j++) scanf ("%c",&Str[i][j]);        GetChar (); } CNT=-1;  for(intI=1; i<=x;i++){             for(intj=1; j<=y;j++){                if(str[i][j]=='.')                    Continue; if(vis[str[i][j]-'A'])                    Continue; if(Judge1 (x,y,i,j,str[i][j]) &&Judge2 (I,J)) {Vis[str[i][j]-'A']=true; ans[++cnt]=Str[i][j]; }}} sort (Ans,ans+1+cnt,cmp); printf ("%s\n", ans); }    return 0;}

HDU 2487 Ugly Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.