zoukankan      html  css  js  c++  java
  • 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
     
    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("
    ");
    }
    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();
        }
    }
  • 相关阅读:
    Ecshop去掉模版中随机出现Ecshop版权的方法
    ecshop邮件订阅按“订阅”没反应
    ecshop开发帮助
    ecshop循环计数
    ECSHOP购物车页面显示商品简单描述
    ecshop 函数列表大全
    ecshop 商品分类页 取得当前分类下的子分类方法
    ecshop调用指定分类和个数的文章列表
    thymeleaf中的th:assert用法
    thymeleaf中的模板布局
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4680939.html
Copyright © 2011-2022 走看看