UVa 1419 Ugly Windows 解题报告(水题)
来源:互联网 发布:淘宝合作协议书 编辑:程序博客网 时间:2024/06/06 03:33
1419 - Ugly Windows
Time limit: 3.000 seconds
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 andm (1n,m100), indicating that the screen hasn lines, and each line consists of m characters.
The following n lines describe the whole screen you see. Each line containsm 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
解题报告: 水题。按顺序枚举字母,在地图中找到第一个该字母的点,向右向下搜索。最后看能不能构成右下角。
唯一要注意的是,窗口可能会嵌套,如下。要判断窗口中有没有其他字母。
7 25.............................DDDDDDDDDDDDD............D...BBB.....D............D...B.B.....D............D...BBB.....D..AAA.......DDDDDDDDDDDDD..A.A......................AAA...
代码如下:
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <set>#include <map>#include <vector>#include <queue>#include <string>#include <iostream>using namespace std;typedef long long LL;typedef unsigned long long ULL;#define ff(i, n) for(int i=0;i<(n);i++)#define fff(i, n, m) for(int i=(n);i<=(m);i++)#define dff(i, n, m) for(int i=(n);i>=(m);i--)void work();int main(){#ifdef ACM freopen("in.txt", "r", stdin);#endif // ACM work();}/****************************************/char maze[111][111];void work(){ int n, m; while(scanf("%d%d", &n, &m) == 2 && (n||m)) { memset(maze, 0, sizeof(maze)); fff(i, 1, n) scanf("%s", maze[i]+1); fff(c, 'A', 'Z') { int t, b, l, r; fff(i, 1, n) fff(j, 1, m) if(maze[i][j] == c) { bool flag = true; t = i, l = j; r = l; while(maze[t][++r] == c); r--; b = t; while(maze[++b][l] == c); b--; fff(k, l, r) if(maze[b][k] != c) flag = false; fff(k, t, b) if(maze[k][r] != c) flag = false; if(r - l < 2) flag = false; if(b - t < 2) flag = false; fff(x, t+1, b-1) fff(y, l+1, r-1) if(maze[x][y] != '.') flag = false; if(flag) putchar(c); i = n + 1, j = m + 1; } } puts(""); }}
- UVa 1419 Ugly Windows 解题报告(水题)
- POJ 3923 Ugly Windows 解题报告
- UVA 1419 - Ugly Windows
- uva 1419 Ugly Windows
- UVA - 1419 Ugly Windows
- UVA 1419 - Ugly Windows(搜索,模拟)
- uva 1419 Ugly Windows(暴力求解)
- uva 1419 - Ugly Windows(暴力)
- LeetCode-Ugly Number-解题报告
- 【LeetCode】Ugly Number 解题报告
- 解题报告:POJ_1338 Ugly Numbers
- Ugly Number系列解题报告
- UVa 1419 - Ugly Windows (DFS + 暴力)
- windows画图(解题报告)
- Uva 11461 - Square Numbers 解题报告(水题)
- UVa 434 - Matty's Blocks 解题报告(水题)
- 【Jason's_ACM_解题报告】Ugly Numbers
- 【ACM菜逼解题报告】Ugly Numbers
- Fragment保存状态
- 容器搜索算法:lower_bound, uper_bound
- 7.23 继续HTML内容及XHTML、CSS的学习
- [Drools]JAVA规则引擎 -- Drools
- ARM7启动代码,文字池
- UVa 1419 Ugly Windows 解题报告(水题)
- epoll小结
- jQuery Ajax 实例 全解析
- oracle 一些基本操作语句
- map容器的用法
- C++调用系统时间
- struct 结构体中对数组和指针的操作细节
- 关于android播放gif图片小总结
- -----------强大的adb--------------