有点坑的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的更多相关文章

  1. Ural 1250 Sea Burial 题解

    目录 Ural 1250 Sea Burial 题解 题意 输入 题解 程序 Ural 1250 Sea Burial 题解 题意 给定一个\(n\times m\)的地图,\(.\)为水,\(\#\ ...

  2. ural 1250. Sea Burial

    1250. Sea Burial Time limit: 1.0 secondMemory limit: 64 MB There is Archipelago in the middle of a s ...

  3. URAL 1250 Sea Burial 简单Floodfill

    问这个人掉落的海域包含几个岛屿. 八方向相连为同一片海域,四方向相连为同一个岛屿.与边界相连的岛屿不算. 方法:在给定地图外面填充一圈".",从这个人掉落的地方开始进行floodf ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  9. 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 ...

随机推荐

  1. Core Bluetooth Programming Guide

    https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth ...

  2. Ant 修改项目pom.xml文件应用

    <?xml version="1.0" encoding="UTF-8"?> <project name="project" ...

  3. 关于百度编辑器UEditor(1.4.3)在C#.NET中的应用实例

    首先去百度UEditor官网下载 1.4.3 .net版本 http://ueditor.baidu.com/build/build_down.php?n=ueditor&v=1_4_3-ut ...

  4. C#中调用unmanaged DLL

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. Bugzilla+MySql+IIS+ActivePerl搭建指南

    头在忙着他的技术研究,对团队建设.测试管理.流程规范都不怎么理会,眼见着产品进入后期整合阶段,在测试过错中出现很多Bug,单靠着我一个人用txt来收集整理bug需求,然后整理成word,放在svn上面 ...

  6. Poj 3982 序列

    1.Link: http://poj.org/problem?id=3982 2.Content: 序列 Time Limit: 1000MS   Memory Limit: 65536K Total ...

  7. 在ThinkPHP3.x框架中实现将原创文章第一时间推送到百度收录

    前两天自己写的一篇文章“针对BootStrap中tabs控件的美化和完善”被别的网站给转载了,这也许是值得高兴的一件事情,但是有些网站并没有注明来源和作者.而去百度搜索这篇文章,排名第一的居然是那些转 ...

  8. GET 和 POST 两种方式来完成Http接口

    程序使用 HTTP 协议和服务器交互主要是进行数据的提交,通常数据的提交是通过 GET 和 POST 两种方式来完成,下面对这两种方式(.net c#)进行一下说明: 1. GET 方式. GET 方 ...

  9. TreeView递归取值

    string jingyuan = ""; string jinghui = ""; private void DiGui(TreeNode tn) { if ...

  10. DTCMS展示一级栏目并展示各自栏目下的二级栏目

    c#代码中 <!--C#代码--> <%csharp%> string parent_id=DTRequest.GetQueryString("parent_id&q ...