zoukankan      html  css  js  c++  java
  • HDU 2487 Ugly Windows

    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 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   |   We have carefully selected several similar problems for you:  2485 2489 2488 2490 2493 
     
     
     
     
     
     
     
     
    #include<stdio.h>//本题唯一的一个坑就是如果一个大窗花里面仍然包含一个小窗户,那么里面的小窗户输出,而外面的窗户不算
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    char str[200][200];
    char ans[200];
    int cnt;
    bool vis[300];
    bool cmp(char t1,char t2){
       return t1<t2;
    }
    int x2,y2;
    int judge1(int n,int m,int x,int y,char c){
         int i=x,j=y;
         while(i<=n&&str[i][j]==c) i++; i--;
         int temp1=i-x;
         while(j<=m&&str[i][j]==c) j++; j--;
         int temp2=j-y;
         x2=i;
         y2=j;
         while(i>=1&&str[i][j]==c) i--; i++;
         while(j>=1&&str[i][j]==c)  j--; j++;
         if(i==x&&j==y&&temp1>=2&&temp2>=2)
            return 1;
         return 0;
    }
    int judge2(int x1,int y1){
       for(int i=x1+1;i<x2;i++){
        for(int j=y1+1;j<y2;j++)
            if(str[i][j]!='.')
            return 0;
       }
       return 1;
    }
    int main(){
        int x,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(int i=1;i<=x;i++){
                for(int j=1;j<=y;j++)
                    scanf("%c",&str[i][j]);
                getchar();
            }
            cnt=-1;
            for(int i=1;i<=x;i++){
                for(int j=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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    perl 解json数组
    华为云3大体系化防护实践,保障金融业云上数据安全
    弹性文件服务解密 -- 块存储、文件存储、对象存储的区别
    【nodejs原理&源码赏析(6)】深度剖析cluster模块源码与node.js多进程
    云+AI+5G时代,华为云已准备好多元化云服务架构
    高能街访 | 为什么他们都纷纷为深圳打Call?
    Angularjs进阶笔记(2)—自定义指令中的数据绑定
    Angularjs进阶笔记(1)—不同类型的双向数据绑定
    ServiceComb java-chassis和CSE java-chassis的区别
    使用inspector功能查看和管理契约
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/4681067.html
Copyright © 2011-2022 走看看