HDU 2487 Ugly Windows(暴力)(2008 Asia Regional Beijing)
Description
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
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
题目大意:给一个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)的更多相关文章
- POJ 3923 HDU 2487 Ugly Windows 简单计算
Ugly Windows Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 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 ...
- 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 ...
- HDU 2487 Ugly Windows
递归求解,代码不太好看,是2013年7月写的 代码: #include<stdio.h> #include<iostream> #include<string.h> ...
- 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 ...
- 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 ...
- 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 ...
- (并查集)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 ...
- (二叉树)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) ...
随机推荐
- GPUImage源码解读之GPUImageFramebufferCache
简介 由于GPUImage添加滤镜可以形成一个FilterChain,因此,在渲染的过程中,可能会需要很多个FrameBuffer,但是正如上文所说,每生成一个FrameBuffer都需要占用一定的内 ...
- 汇编中PSP是什么?为什么一般cs比ds大10h
一般来说,PSP是256个字节,当程度生成了可执行文件以后,在执行的时候,先将程序调入内存, 这个时候DS中存入程序在内存中的段地址,紧接着是程序的一些说明,比如说程序占用多大空间等 等,这就是PSP ...
- Linux中文件函数(一)
一.stat.fstat.fstatat.lstat函数 函数的原型为: #include <sys/stat.h> int stat(const char *restrict pathn ...
- Linux在线安装jdk8,并配置环境变量
1.创建相关目录:下载目录.安装目录 下载目录: cd / 2.下载jdk8到目录 下载前先跳转到下载目录,比如希望最后压缩包下载到/home/bak/下, 则先创建bak目录,命令如下: 注意:如果 ...
- 第四模块MySQL50题作业,以及由作业引申出来的一些高端玩法
一.表关系 先参照如下表结构创建7张表格,并创建相关约束 班级表:class 学生表:student cid caption grade_id ...
- 如何利用Linux去油管下载带字幕的优质英文资料提升英文听力和词汇量
非常方便地从油管下载你需要的任何英文视频资料,并且带字幕,方便你学习某个特定领域的词汇: [step1,Centos6系统安装youtbe-dl下载带英文字幕的视频] 1.首先需要安装youtube- ...
- 开发和调试第一个 LLVM Pass
1. 下载和编译 LLVM LLVM 下载地址 http://releases.llvm.org/download.html,目前最新版是 6.0.0,下载完成之后,执行 tar 解压 llvm 包: ...
- 线上服务内存OOM问题定位三板斧
相信大家都有感触,线上服务内存OOM的问题,是最难定位的问题,不过归根结底,最常见的原因: 本身资源不够 申请的太多 资源耗尽 58到家架构部,运维部,58速运技术部联合进行了一次线上服务内存OOM问 ...
- collections.Counter类统计列表元素出现次数
# 使用collections.Counter类统计列表元素出现次数 from collections import Counter names = ["Stanley", &qu ...
- python和java,php,c,c#,c++的对比
1.C语言,它既有高级语言的特点,又具有汇编语言的特点,它是结构式语言.C语言应用指针:可以直接进行靠近硬件的操作,但是C的指针操作不做保护,也给它带来了很多不安全的因素.C++在这方面做了改进,在保 ...