zoukankan      html  css  js  c++  java
  • poj_3923Ugly Windows

    Ugly Windows
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 962   Accepted: 287

    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
    模拟水题吧

    #include <iostream>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <algorithm>
    using namespace std;
    #pragma warning(disable : 4996)
    #define MAX 200
    char map[MAX][MAX] = {0};
    
    bool check(int x, int y, int x_len, int y_len)
    {
    	for(int i = x + 1; i <= x_len + x - 1; i++)
    	{
    		for(int j = y + 1; j <= y_len + y - 2; j++)
    		{
    			if(map[i][j] != '.')
    			{
    				return false;
    			}
    		}
    	}
    	return true;
    }
    
    int main()
    {
    	freopen("in.txt", "r", stdin);
    	int x, y, z, k, n, m;
    	char c;
    	vector<char>ans;
    	while (cin >> n >> m)
    	{
    		memset(map, 0, sizeof(map));
    		if(n == 0 && m == 0)
    		{
    			break;
    		}
    		for(int i = 1; i <= n; i++)
    		{
    			for(int j = 1; j <= m; j++)
    			{
    				cin >> map[i][j];
    			}
    		}
    		for(int i = 1; i <= n; i++)
    		{
    			for(int j = 1; j <= m; j++)
    			{
    				c = map[i][j];
    				if(c != '.' && map[i][j+1] == c && map[i+1][j] == c && map[i][j+2] == c && map[i+2][j] == c)
    				{
    					x = 0, y = 0, z = 0, k = 0;
    					int p = i, q = j;
    					while(map[p][q] == c)
    					{
    						x++;
    						map[p][q] = '.';
    						q++;
    					}
    					if(x < 3) continue;
    					q--;
    					p++;
    					while(map[p][q] == c)
    					{
    						y++;
    						map[p][q] = '.';
    						p++;
    					}
    					if(y < 2) continue;
    					p--;
    					q--;
    					while(map[p][q] == c)
    					{
    						z++;
    						map[p][q] = '.';
    						q--;
    					}
    					if(z < 2) continue;
    					q++;
    					p--;
    					while(map[p][q] == c)
    					{
    						k++;
    						map[p][q] = '.';
    						p--;
    					}
    					if(k < 1) continue;
    					if(check(i, j, y, x) && p == i && q == j && (x + y + z + k) % 2 == 0 && x == z + 1 && y == k + 1 && x >= 3 && y >= 2 && z >= 1 && k >= 1)
    					{
    						ans.push_back(c);
    					}
    				}
    			}
    		}
    		sort(ans.begin(), ans.end());
    		for(int i = 0; i < ans.size(); i++)
    		{
    			cout << ans[i];
    		}
    		cout << endl;
    		ans.clear();
    	}
    	return 0;
    }


  • 相关阅读:
    Android 隐式意图激活另外一个Actitity
    Android 显示意图激活另外一个Actitity
    Android 创建一个新的Activity
    调用meitu秀秀.so文件实现美图功能
    Android C代码回调java方法
    Android 在C代码中调用logcat
    Android java传递int类型数组给C
    Android java传递string类型数据给C
    使用pywin32处理excel文件
    利用 pywin32 操作 excel
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835105.html
Copyright © 2011-2022 走看看