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. 

题目大意:给一个n*m的矩阵,每一个字母代表一个窗口的边框,问那些窗口在最顶端(这题太难描述了不管了……)

思路:这题数据范围很小,就不用那些很难写但速度可能比较快的算法了,因为是水题写得快和准更重要。首先枚举每一个字母,找出每一个字母最大和最小的x、y坐标,检查一下这个字母的窗口边框是不是都是那个字母,再检查一下这个窗口里面有没有被其他奇怪的东西覆盖(就是都要是'.'),就能AC了。

PS:把一个max_y打成了max_x又WA了一个>_<

代码(0MS):

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAX = ; char mat[MAX][MAX];
int n, m; bool top(char c) {
int max_x = , min_x = MAX, max_y = , min_y = MAX;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
if(mat[i][j] != c) continue;
max_x = max(max_x, j);
min_x = min(min_x, j);
max_y = max(max_y, i);
min_y = min(min_y, i);
}
}
if(max_x - min_x < || max_y - min_y < ) return false;
for(int i = min_y; i <= max_y; ++i)
if(mat[i][max_x] != c || mat[i][min_x] != c) return false;
for(int i = min_x; i <= max_x; ++i)
if(mat[max_y][i] != c || mat[min_y][i] != c) return false;
for(int i = min_y + ; i < max_y; ++i) {
for(int j = min_x + ; j < max_x; ++j)
if(mat[i][j] != '.') return false;
}
return true;
} int main() {
while(scanf("%d%d", &n, &m) != EOF) {
if(n == && m == ) break;
for(int i = ; i <= n; ++i) scanf("%s", &mat[i][]);
for(char c = 'A'; c <= 'Z'; ++c)
if(top(c)) printf("%c", c);
puts("");
}
}

HDU 2487 Ugly Windows(暴力)(2008 Asia Regional Beijing)的更多相关文章

  1. POJ 3923 HDU 2487 Ugly Windows 简单计算

    Ugly Windows Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. HDU 2489 Minimal Ratio Tree(暴力+最小生成树)(2008 Asia Regional Beijing)

    Description For a tree, which nodes and edges are all weighted, the ratio of it is calculated accord ...

  3. HDU 2494/POJ 3930 Elevator(模拟)(2008 Asia Regional Beijing)

    Description Too worrying about the house price bubble, poor Mike sold his house and rent an apartmen ...

  4. HDU 2487 Ugly Windows

    递归求解,代码不太好看,是2013年7月写的 代码: #include<stdio.h> #include<iostream> #include<string.h> ...

  5. HDU 2490 Parade(DPの单调队列)(2008 Asia Regional Beijing)

    Description Panagola, The Lord of city F likes to parade very much. He always inspects his city in h ...

  6. HDU 2492 Ping pong(数学+树状数组)(2008 Asia Regional Beijing)

    Description N(3<=N<=20000) ping pong players live along a west-east street(consider the street ...

  7. HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)

    Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...

  8. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  9. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

随机推荐

  1. Vue--- 一点车项目 6个小时实际看了10天(完结)

    一个项目 环境安装   使用了 cli 脚手架  Koa2  workpackage  其他小的不计 前端Vue组件搭建 数据的简单测试交互 数据库的设计 创建.连接接数据库 前台[表单/分类]   ...

  2. 第一个electron

    1 开发环境:node环境 2 下载electron:npm install electron --save-dev 3 package.json配置如下: { "name": & ...

  3. 断言assert()与调试帮助

    列表内容assert()是一种预处理宏(preprocessor marco),使用一个表达式来作为条件,只在DEBUG模式下才有用. assert(expr); 对expr求值,如果expr为假,则 ...

  4. 浅谈HashMap与线程安全 (JDK1.8)

    HashMap是Java程序员使用频率最高的用于映射(键值对)处理的数据类型.HashMap 继承自 AbstractMap 是基于哈希表的 Map 接口的实现,以 Key-Value 的形式存在,即 ...

  5. Java开发小技巧(五):HttpClient工具类

    前言 大多数Java应用程序都会通过HTTP协议来调用接口访问各种网络资源,JDK也提供了相应的HTTP工具包,但是使用起来不够方便灵活,所以我们可以利用Apache的HttpClient来封装一个具 ...

  6. 指针小白:修改*p与p会对相应的地址的变量产生什么影响?各个变量指针的长度为多少?

    这两天敲代码碰到了一个这样的问题 代码如下: #include <stdio.h> #include <stdlib.h> int main() { ; int* p=& ...

  7. 小Hi和小Ho的礼物

    题目:小Hi和小Ho的礼物 注:[i.j.p.q]为下标 个人感觉这道题是有一定难度的.读者可以参考一下[四平方和]的解题思路 分析过程下次补上 代码如下: #include <iostream ...

  8. HyperLedger Fabric 1.4 多机多节点部署(10.3)

    多机多节点指在多台电脑上部署多个组织和节点,本案例部署一个排序(orderer)服务,两个组织(org1,org2)和四个节点(peer),每个组织包括两个节点,需要五台计算机,计算机配置如下: 多机 ...

  9. macos 安装 brew

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ...

  10. canvas画的文字在安卓移动设备上可以显示,但是在ios移动设备上无法显示

    不用担心iOS Safari不支持canvas,查看https://caniuse.com/ 发现是支持的 ctx.font = "0.16rem Arial"; 为了适配移动端直 ...