HDUOJ----2487Ugly Windows
Ugly Windows
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1199 Accepted Submission(s): 467
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
代码:
1 #include<iostream>
2 #include<vector>
3 using namespace std;
4 const int maxn=1002;
5 const int NN=102;
6 char win[NN][NN];
7 typedef struct windows
8 {
9 int x,y;
10 }ww;
11 int n,m;
12 void work()
13 {
14 int min_x,max_x,min_y,max_y,i,j;
15 char ch;
16 vector<ww>aa;
17 ww temp;
18 for(ch='A'; ch<='Z';ch++)
19 {
20 aa.clear();
21 min_x=min_y=maxn;
22 max_x=max_y=0;
23 for(i=0;i<n;i++) //---> y
24 {
25 for(j=0;j<m;j++) //--->x
26 {
27 if(ch==win[i][j]) //这样就存储了一个图
28 {
29 temp.x=j+1;
30 temp.y=i+1;
31 aa.push_back(temp);
32 }
33 }
34
35 }
36 /*华丽丽的分割线对这个图进行分析找到他的四个极点*/
37 if(aa.size()==0) continue ; //说明没有这个windows
38 for(i=0 ;i<aa.size();i++ )
39 {
40 if(max_x<aa[i].x) max_x=aa[i].x;
41 if(max_y<aa[i].y) max_y=aa[i].y;
42 if(min_x>aa[i].x) min_x=aa[i].x;
43 if(min_y>aa[i].y) min_y=aa[i].y;
44 }
45 if((max_x-min_x)<2||(max_y-min_y)<2||2*(max_x-min_x+max_y-min_y)!=aa.size()) continue;
46 bool tag=false;
47 for(i=min_y;i<(max_y-1);i++)
48 {
49 for(j=min_x;j<(max_x-1);j++)
50 {
51 if(win[i][j]>='A'&&win[i][j]<='Z') //判断是否在在框内有顶点框
52 {
53 tag=true;
54 goto loop;
55 }
56 }
57 }
58 loop:
59 if(!tag) cout<<ch;
60 }
61 cout<<endl;
62 }
63 int main()
64 {
65 // int n,m;
66 int i,j;
67 while(cin>>n>>m,n+m)
68 {
69
70 for( i=0 ; i<n ; i++ )
71 {
72 for( j=0 ; j<m ; j++)
73 cin>>win[i][j];
74 }
75
76 work();
77 }
78 return 0;
79 }
- Python编程语言发展简史
- 学完Python基础知识后,你真的会python吗?
- 一个人的武林:内网渗透测试思路(二)
- Python数据分析之股票实战
- 这货不是电源:硬件渗透测试平台 – Power Pwn
- Python进阶学习之阅读代码
- 代码安全审计:当file_exists遇上eval
- Python 异常处理完整指南
- 有趣的安全实验:利用多线程资源竞争技术上传shell
- NotSerializableException解决方法NotSerializableException
- 谁蹭了我的WiFi?浅谈家用无线路由器攻防
- 当输入流和输出流同时作用一个文件
- 揭秘:充电宝是如何盗取你的个人隐私的?
- 微软:暴力破解面前,增强密码复杂性基本没用
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- [白话解析] 深入浅出最大熵模型
- [白话解析] 带你一起梳理Word2vec相关概念
- 利用SSE服务器主动向浏览器端发送消息
- [白话解析] Flink的Watermark机制
- [源码分析] 从源码入手看 Flink Watermark 之传播过程
- [白话解析]以水浒传为例学习隐马尔可夫模型
- [白话解析]用水浒传为例学习最大熵马尔科夫模型
- [白话解析] 用水浒传为例学习条件随机场
- 03.Android崩溃Crash库之ExceptionHandler分析
- 04.Android崩溃Crash库之Loop拦截崩溃和ANR
- [源码分析] 从实例和源码入手看 Flink 之广播 Broadcast
- [源码分析] 从FlatMap用法到Flink的内部实现
- [白话解析] 通俗解析集成学习之bagging,boosting & 随机森林
- [源码分析] 带你梳理 Flink SQL / Table API内部执行流程
- 从"UDF不应有状态" 切入来剖析Flink SQL代码生成