HDU 2487 Ugly window

这是切的很痛苦的一道题,自己测试了很多样例却终究不过,中间也做了诸多修改,后来无奈去网上看题解,发现遗漏了一种情况,就是两个窗口可能边框都能看见,但是一个嵌套在另一里面,而我判定是不是 “top window”的条件只要是边框全部暴露在外面,所以呢发现边框完整没有遮挡的时候,对边框包围区域遍历一遍看里面有没有字母,这样就能判定一个“top window”了。
主要思路就是沿着右下左上的方向行进,遇到不是相同字母或越界的情况就变化方向,如果提前表示方向的d>3,说明边框被遮挡不完整,若完整的话对框内区域进行查找看有没有其他字母。
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define N 110 char maze[N][N];
5 int vis[N][N];
int ans[];
int dx[]= {,,,-};
int dy[]= {,,-,};
int n,m,d; int find(int x,int y,int s,int t)
{
int i,j;
for(i=x+;i<s;i++)
for(j=y+;j<t;j++)
if(isalpha(maze[i][j]))
return ;
return ;
} void dfs(int x,int y,int c)
{
int nx,ny;
nx=x+dx[d];
ny=y+dy[d];
int s=x,t=y,p,q;
while()
{
if(nx==s&&ny==t&&d==&&maze[nx][ny]==c&&vis[nx][ny]&&fa[nx][ny]==nx*m+ny)
{
if(!find(s,t,p,q))
ans[c-'A']=;
else ans[c-'A']=-;
return;
}
while(nx<||nx>=n||ny<||ny>=m||maze[nx][ny]!=c||vis[nx][ny])
{
d++;
if(d>)
{
ans[c-'A']=-;
return;
}
if(d==)
p=x,q=y;
nx=x+dx[d];
ny=y+dy[d];
} vis[x][y]=;
x=nx;
y=ny;
if(nx==s&&ny==t&&d==&&maze[nx][ny]==c&&vis[nx][ny]&&fa[nx][ny]==nx*m+ny)
{
ans[c-'A']=;
return;
}
nx=x+dx[d];
ny=y+dy[d];
}
} int main(void)
{
int i,j,c;
while(scanf("%d%d",&n,&m)&&(n||m))
{
memset(fa,-,sizeof(fa));
memset(ans,,sizeof(ans));
memset(maze,,sizeof(maze));
memset(vis,,sizeof(vis));
for(i=; i<n; i++)
scanf("%s",maze[i]);
for(i=; i<n; i++)
for(j=; j<m; j++)
{
c=maze[i][j];
if(c>='A'&&c<='Z'&&!ans[c-'A'])
{
fa[i][j]=i*m+j;
d=;
dfs(i,j,c);
}
}
for(i=; i<; i++)
if(ans[i]==)
putchar(i+'A');
puts("");
}
return ;
}
HDU 2487 Ugly window的更多相关文章
- 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 ...
- HDU 2487 Ugly Windows
递归求解,代码不太好看,是2013年7月写的 代码: #include<stdio.h> #include<iostream> #include<string.h> ...
- Ugly Window 【acm题】
话说好久没有碰acm题目了.............................. 看到Ugly Window这道题目,没有多想,就直接先找到字母的连续长度和连续高度,并统计该字母的总个数,然后用 ...
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU - 5920 Ugly Problem 求解第一个小于n的回文数
http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...
- HDU 5920 Ugly Problem
说起这道题, 真是一把辛酸泪. 题意 将一个正整数 \(n(\le 10^{1000})\) 分解成不超过50个回文数的和. 做法 构造. 队友UHC提出的一种构造方法, 写起来比较方便一些, 而且比 ...
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- 【HDOJ】2487 Ugly Windows
暴力解. #include <cstdio> #include <cstring> #define MAXN 105 char map[MAXN][MAXN]; ]; int ...
随机推荐
- %s 与 %0s在 verilog中的区别
what is different between %s and %0s?(%s和%零s) %s prints the string as it is with spaces at the begin ...
- Yii框架页面运行流程
Yii框架页面运行流程 CComponent | CModel | CActiveRecord.CFormModel(所有模型的父类) | 表名.php(模型) | 入口文件------------- ...
- INI文件的读写
public class INIoperation { string inipath = Utils.GetMapPath("/Integration/Sync/set.ini") ...
- rc4加密
function RC4(Expression, Password: string): string; var RB : array[0..255] of Integer; X, Y, Z: long ...
- ios 相册相关
1.ALAssetsLibrary 系统中的资源库,可以使用他来访问资源库中的资源,照片.视屏等. [ALAssetsLibrary authorizationStatus];获取当前应用能否 ...
- IOS_视图实现圆角效果的三种方法及比较
通过代码,至少有三种方法可以为视图加上圆角效果.附例子:https://github.com/weipin/RoundedCorner 方法一.layer.cornerRadius 第一种方法最简单, ...
- android studio安装后卡在fetching Android sdk compoment information
解决办法: 找到android studio 安装目录下bin目录中(D:\Android\Android Studio\bin)的idea.properties文件,在文件末尾处添加disable. ...
- linux管道学习(一)
最近学习了管道 pipe,在这里进行一下总结. 这里贴一段自己的实做代码 struct node{ int a; long b; }; int main() { ]; pid_t pid; ]; in ...
- Unix环境高级编程学习笔记——fcntl
写这篇文正主要是为了介绍下fcntl,并将我自己在学习过程中的一些理解写下来,不一定那么官方,也有错误,希望指正,共同进步- fcntl: 一个修改一打开文件的性质的函数.基本的格式是 int fcn ...
- js获取任意元素到页面的距离
function getPos(obj){ var pos={left:0,top:0} while(obj){ pos.left+=obj.offsetLeft; pos.top+=obj.offs ...