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 ...
随机推荐
- mysql 主从同步 M-S 搭建
主机: [root@ygy130 ~]# mysql -usystem -p123456 mysql> create database HA; mysql> use HA; mysql&g ...
- Centos +django+nginx
WSGI配置 #!/usr/bin/python """ WSGI config for rana project. It exposes the WSGI callab ...
- Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio
In previous posts on vm.swappiness and using RAM disks we talked about how the memory on a Linux gue ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索
A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...
- stout代码分析之八:cache类
stout中实现了LRU cache.cache的成员如下: public: typedef std::list<Key> list; typedef std::tr1::unordere ...
- gitlab 的使用策略和简单介绍
gitlab 作为版本控制器,基本使用和github 相同,以下是一些策略和介绍: Git 分支管理策略可以参考下面三个链接: http://www.ruanyifeng.com/blog/2012/ ...
- Ajax请求回调函数没有被调用
$.ajax({ type:"post", url:"http://172.16.41.91:8080/FcsServletSSM/users ...
- POJ 3255 Roadblocks (次短路模板)
Roadblocks http://poj.org/problem?id=3255 Time Limit: 2000MS Memory Limit: 65536K Descriptio ...
- 地精排序Gnome Sort
号称最简单的排序算法,只有一层循环,默认情况下前进冒泡,一旦遇到冒泡的情况发生就往回冒,直到把这个数字放好为止 直接看它排序的过程,待排数组[6 2 4 1 5 9] 先设计一个标识i=0然后从头开始 ...
- bzoj 2079: [Poi2010]Guilds——结论题
Description Zy皇帝面临一个严峻的问题,两个互相抵触的贸易团体,YYD工会和FSR工会,他们在同一时间请求在王国各个城市开办自己的办事处.这里有n个城市,其中有一些以双向马路相连,这两个工 ...