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 ...
随机推荐
- Linux上安装Oracle11g
1.首先是挂盘 1.1 Linux硬盘挂载步骤:查看磁盘 先查看目前机器上有几块硬盘,查看命令有两种: 命令1:# fdisk –l 命令2:# dmesg | grep sd 其中:fdisk命令说 ...
- 信息工程学院技能大赛 计算机程序设计(Java)大赛试题
前期准备与后期上传工作: (1)必须先建立项目和包,项目名为"JavaContest",包结构为:"contest.c+序号+姓名",其中序号为两位为本人大赛报 ...
- 平衡二叉树 (牛客国庆day2)解锁二叉树打表姿势&&找规律套路
链接:https://www.nowcoder.com/acm/contest/202/F来源:牛客网 平衡二叉树,顾名思义就是一棵“平衡”的二叉树.在这道题中,“平衡”的定义为,对于树中任意一个节点 ...
- LruCache:从网络加载图片缓存实例
OOM异常 堆内存用于存储实例对象,当程序不断创建对象,并且对象都有引用指向,那么垃圾回收机制就不会清理这些对象,当对象多到挤满堆内存的上限后,就产生OOM异常.Android系统为每个应用程序使用的 ...
- HDU1394 逆序数
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- ios开关按钮
.al-toggle-button{ appearance: none; -webkit-appearance: none; position: relative; width: 52px; heig ...
- 通过psexec实现远程安装软件包
1.在管理机上下载和安装psexec https://docs.microsoft.com/en-us/sysinternals/downloads/psexec 2.在管理机上编写bat脚本,存放在 ...
- Stick footers布局总结
一.Sticky footers解释 在网页设计中,Sticky footers设计是最古老和最常见的效果之一,大多数人都曾经经历过.它可以概括如下:如果页面内容不够长的时候,页脚块粘贴在视窗底部:如 ...
- [USACO06NOV] Roadblocks
https://www.luogu.org/problem/show?pid=2865 题目描述 Bessie has moved to a small farm and sometimes enjo ...
- 如何查看由EF生成的SQL?
如下: query = from c in query group c by c.Id into cGroup orderby cGroup.Key select cGroup.FirstOrDefa ...