HDU-2487
Ugly Windows
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1474 Accepted Submission(s): 588
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?
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.
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
/**
题意:给一个图,然后判断是哪一个图在上边,并且该框是>=3*3
做法:模拟
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <queue>
#define maxn 110
using namespace std;
int vis[maxn][maxn];
int dx[] = {,,-,};
int dy[] = {,-,,};
char ch[maxn][maxn];
int alp[];
struct Node
{
int x;
int y;
} node[maxn];
struct NN
{
int x[];
int y[];
char c[];
} no[];
int n,m;
int check(int x,int y)
{
if(x >= && x < n && y >= && y < m && vis[x][y] == ) return ;
return ;
}
int bfs(int x,int y)
{
queue<Node>que;
Node tmp,now;
vis[x][y] = ;
tmp.x = x;
tmp.y = y;
char c = ch[x][y];
que.push(tmp);
int sum = ;
while(!que.empty())
{
now = que.front();
que.pop();
for(int i=; i<; i++)
{
tmp.x = now.x + dx[i];
tmp.y = now.y + dy[i];
if(check(tmp.x,tmp.y) && ch[tmp.x][tmp.y] == c)
{
vis[tmp.x][tmp.y] = ;
que.push(tmp);
sum++;
}
}
}
return sum;
}
int solve()
{
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
int num1 = ;
int num2 = ;
int num = ;
int res = ;
if(ch[i][j] != '.' && vis[i][j] == )
{
char c = ch[i][j];
for(int ii = i; ii<n; ii++)
{
if(ch[ii][j] == c) num1++;
else break;
}
for(int jj= j; jj<m; jj++)
{
if(ch[i][jj] == c) num2++;
else break;
}
num = bfs(i,j);
if(num == *( num1 + num2 -) && num1 >= && num2 >= && num >= )
{
int tt = ch[i][j] - 'A';
alp[tt] = ;
no[tt].x[] = i;
no[tt].x[] = i+ num1 -;
no[tt].y[] = j;
no[tt].y[] = j + num2 -;
}
}
}
}
for(int i=; i<; i++)
{
if(alp[i] == )
for(int j=; j<; j++)
{
if(alp[j] == && no[i].x[] < no[j].x[] && no[i].x[] > no[j].x[] && no[i].y[]< no[j].y[] && no[i].y[] > no[j].y[])
{
alp[i] = ;
// break;
}
}
}
for(int i=; i<; i++)
{
if(alp[i])
{
printf("%c",i+'A');
}
}
printf("\n");
}
int main()
{
// freopen("in.txt","r",stdin);
while(~scanf("%d %d",&n,&m))
{
if(n == && m == ) break;
for(int i=; i<n; i++)
{ scanf("%s",ch[i]); }
memset(vis,,sizeof(vis));
memset(alp,,sizeof(alp));
solve();
}
}
HDU-2487的更多相关文章
- HDU 2487 Ugly Windows
递归求解,代码不太好看,是2013年7月写的 代码: #include<stdio.h> #include<iostream> #include<string.h> ...
- HDU 2487 Ugly window
这是切的很痛苦的一道题,自己测试了很多样例却终究不过,中间也做了诸多修改,后来无奈去网上看题解,发现遗漏了一种情况,就是两个窗口可能边框都能看见,但是一个嵌套在另一里面,而我判定是不是 “top wi ...
- POJ 3923 HDU 2487 Ugly Windows 简单计算
Ugly Windows Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 2487 Ugly Windows(暴力)(2008 Asia Regional Beijing)
Description Sheryl works for a software company in the country of Brada. Her job is to develop a Win ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- BZOJ2821:作诗——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2821 问题描述 神犇SJY虐完HEOI之后给傻×LYD出了一题: SHY是T国的公主,平时的一大爱好 ...
- mybatis中parameterType可以写的别名
mybatis中parameterType可以写的别名 https://blog.csdn.net/sdzhangshulong/article/details/51749807 _byte byte ...
- Ubuntu16.04 U盘安装Ubuntu16.04制作 光盘刻录 安装与简介
从今天开始,我会把我遇到过的技术问题一一记录下来,从而分享给有需要的朋友,尽量希望你们少走弯路! 一.首先从官网上下载Ubuntu16.04镜像,下载最好从官网上下载(http://www.ubunt ...
- 关闭nginx日志
在nginx.conf中将 access_log /dev/null; error_log /dev/null;
- bzoj 1131 [POI2008]Sta 树形dp 转移根模板题
[POI2008]Sta Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1889 Solved: 729[Submit][Status][Discu ...
- android极光推送初步了解
推送可以及时,主动的与用户发起交互 (1)继承jar包,照示例AndroidManifest.xml添加. (2)自定义MyApp继承自Application,在onCreate方法中调用JPushI ...
- 【51NOD-0】1118 机器人走方格
[算法]DP #include<cstdio> #include<algorithm> using namespace std; ,maxn=; int f[maxn][max ...
- Lua中调用C++方法
目前项目,使用了Lua脚本,至于使用Lua的好处不再赘述了.于是对Tolua做了一些小小的学习,总结一下吧. 主要说一下如何在Lua中调用C++方法. Lua调用C++的桥梁,是tolua.tolua ...
- 【洛谷 P5110】 块速递推(矩阵加速,分块打表)
题目链接 掌握了分块打表法了.原来以前一直想错了... 块的大小\(size=\sqrt n\),每隔\(size\)个数打一个表,还要在\(0\text{~}size-1\)每个数打一个表. 然后就 ...
- 转一篇sublime必备的一些插件
Package Control 功能:安装包管理 简介:sublime插件控制台,提供添加.删除.禁用.查找插件等功能 使用:https://sublime.wbond.net/installatio ...