ural 1250
有点坑的dfs 看懂题应该就会做了 神圣海必然围成一个圈 dfs将神圣还外围的全部去掉 简单题
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
int dx[] = {1, 1, 1, -1, -1, -1, 0, 0};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int ex[] = {1, -1, 0, 0};
int ey[] = {0, 0, 1, -1};
int g[510][510],w,h;
bool ok(int x, int y)
{
if(x >= 1 && y >= 1 && x <= h && y <= w)
return true;
return false;
}
void dfs1(int x, int y)
{
if(g[x][y] == 1)
{
g[x][y] = 2;
for(int i = 0; i < 8; i++)
{
int nx = x+dx[i], ny = y+dy[i];
if(ok(nx,ny))
dfs1(nx, ny);
}
}
}
void dfs2(int x, int y)
{
if(g[x][y] != 2 && g[x][y] != 3)
{
g[x][y] = 3;
for(int i = 0; i < 4; i++)
{
int nx = x+ex[i], ny = y+ey[i];
if(ok(nx,ny))
dfs2(nx, ny);
}
}
}
void dfs3(int x, int y)
{
if(g[x][y] == 0)
{
g[x][y] = 1;
for(int i = 0; i < 4; i++)
{
int nx = x+ex[i], ny = y+ey[i];
if(ok(nx,ny))
dfs3(nx, ny);
}
}
}
int main()
{
int x,y;
char c;
scanf("%d%d%d%d",&w,&h,&x,&y);
getchar();
memset(g, 0, sizeof(g));
for(int i = 1; i <= h; i++)
{
for(int j = 1; j <= w; j++)
{
scanf("%c",&c);
if(c == '.')
g[i][j] = 1;
}
getchar();
}
dfs1(y, x);
for(int i = 1; i <= w; i++)
{
if(g[1][i] != 2)
dfs2(1, i);
if(g[h][i] != 2)
dfs2(h, i);
}
for(int i = 1; i <= h; i++)
{
if(g[i][1] != 2)
dfs2(i, 1);
if(g[i][w] != 2)
dfs2(i, w);
}
int ans = 0;
for(int i = 1; i <= h; i++)
for(int j = 1; j <= w; j++)
{
if(!g[i][j])
{
dfs3(i, j);
ans++;
}
}
printf("%d\n",ans);
return 0;
}
ural 1250的更多相关文章
- Ural 1250 Sea Burial 题解
目录 Ural 1250 Sea Burial 题解 题意 输入 题解 程序 Ural 1250 Sea Burial 题解 题意 给定一个\(n\times m\)的地图,\(.\)为水,\(\#\ ...
- ural 1250. Sea Burial
1250. Sea Burial Time limit: 1.0 secondMemory limit: 64 MB There is Archipelago in the middle of a s ...
- URAL 1250 Sea Burial 简单Floodfill
问这个人掉落的海域包含几个岛屿. 八方向相连为同一片海域,四方向相连为同一个岛屿.与边界相连的岛屿不算. 方法:在给定地图外面填充一圈".",从这个人掉落的地方开始进行floodf ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
随机推荐
- Span flag详解
在android中,如果要实现text的各种样式,图文混排等,简单的样式可以靠几个不同的textview来拼成,而复杂的样式要求,用不同的textview来拼接则不太现 实.这时候就spannable ...
- ubuntu 阿里云安全配置
1. 添加新用户, 加入 root 组, 赋予 sudo 权限 2. 禁用 root 3.
- js 中的正则表达式
一:正则表达式 定义:记录文本规则的代码 作用:表单验证,爬虫技术,可以对目标的内容进行替换. 二:正则表达式的组成 1:普通字符组成正则 浏览器的输出 2:定义字符集组成正则 3:特殊字符集组成正则 ...
- VM 打开虚拟机时报“内部错误”
VM 打开虚拟机时报“内部错误” 你是直接双击VM软件吗? 试下右键用管理员身份打开VM吧 是不是成功了 不成功不要找我,我就是这样成功的,就自己记录下
- Call与Apply
1.前言 ECMAscript中提供了两个方法(call,apply)用于改变对象内部的this指针,它们两个的作用都是一样的,但是传递的参数有点不大相同. 它们的大概语法为: call(this, ...
- bootstrap-validator使用
bootstrap-validator是一款与bootstrap相结合的表单前端验证模块,官方网址:http://1000hz.github.io/bootstrap-validator/ 下面内容大 ...
- 使用spring手动控制事务
http://kiral.iteye.com/blog/92742 使用spring手动控制事务 Spring事务配置的五种方式 (1) http://www.cnblogs.com/hellojav ...
- 【转】 c++拷贝构造函数(深拷贝,浅拷贝)详解
c++拷贝构造函数(深拷贝,浅拷贝)详解 2013-11-05 20:30:29 分类: C/C++ 原文地址:http://blog.chinaunix.net/uid-28977986-id-3 ...
- MIT 2012 分布式课程基础源码解析-底层通讯实现
本节内容和前节事件管理封装是息息相关的,本节内容主要包含的代码在connection{.h, .cc}中. 这里面最主要的有两个类:connection类和tcpsconn类,connetion类主要 ...
- 将Ecshop后台fckeditor升级更改为kindeditor 4.1.10编辑器
ecshop在win8部分电脑上,不管用任何浏览器,都打不开,即使升级到最新版本都不行,问题应该吃在fckeditor兼容上.fckeditor 很久未升级,换掉该编辑器是最佳方法 第一步:下载kin ...