题目

找最大的一片湖的面积,4便有1边相连算相连,4角不算。

runtime error 有一种可能是 数组开的太小,越界了

#define  _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 110
int map[MAXN][MAXN];
int n,m,sum,a[MAXN*MAXN],b[MAXN*MAXN];//runtime error 原来是这里小了
int xx[]={,,,-};
int yy[]={,-,,};
struct tt
{
int x,y;
}; int bfs()
{
int ans,maxx=;
tt front,rear,temp;
queue<tt>q;
while(!q.empty())
q.pop();
for(int i=;i<sum;i++)
{
if(map[a[i]][b[i]]==)
{
front.x=a[i];front.y=b[i];
q.push(front);
map[a[i]][b[i]]=;
ans=;
while(!q.empty())
{
temp=q.front();
q.pop();
for(int j=;j<;j++)
{
rear.x=temp.x+xx[j];
rear.y=temp.y+yy[j];
if(rear.x>&&rear.y>&&rear.x<=n&&rear.y<=m&&map[rear.x][rear.y]==)
{
q.push(rear);
map[rear.x][rear.y]=;
ans++;
maxx=maxx>ans? maxx:ans;
}
}
}
}
}
return maxx;
} int main()
{
int i;
while(scanf("%d%d%d",&n,&m,&sum)!=EOF)
{
memset(map,,sizeof(map));
for(i=;i<sum;i++)
{
scanf("%d%d",&a[i],&b[i]);
map[a[i]][b[i]]=;
}
printf("%d\n",bfs());
} return ;
}

poj 3620 Avoid The Lakes(广搜,简单)的更多相关文章

  1. poj 3620 Avoid The Lakes【简单dfs】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6795   Accepted: 3622 D ...

  2. [深度优先搜索] POJ 3620 Avoid The Lakes

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 4270 D ...

  3. POJ 3620 Avoid The Lakes【DFS找联通块】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6826   Accepted: 3637 D ...

  4. POJ 3620 Avoid The Lakes

    http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...

  5. POJ 3620 Avoid The Lakes(dfs算法)

    题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...

  6. POJ 3620 Avoid The Lakes (求连接最长的线)(DFS)

    Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the i ...

  7. POJ 2251 Dungeon Master(广搜,三维,简单)

    题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...

  8. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  9. poj 3026 Borg Maze 最小生成树 + 广搜

    点击打开链接 Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7097   Accepted: 2389 ...

随机推荐

  1. JavaScript 弹窗

    JavaScript 弹窗 可以在 JavaScript 中创建三种消息框:警告框.确认框.提示框. 警告框 警告框经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行 ...

  2. mobileconfig文件的签名和认证(signed、verified)

    专题:基于IOS上MDM技术相关资料整理及汇总mobileconfig文件的签名和认证(signed.verified) 一.功能描述: 鉴于我们的设备和MDM server之间已经可以通信,并能完成 ...

  3. 用canvas 绘制的饼状统计图、柱状统计图、折线统计图

    canvas 绘制的饼状统计图 canvas 绘制的柱状统计图 canvas 绘制的折线统计图

  4. javascript面向对象--自定义类型

    Javascript是基于原型实现面向对象的,因此并没有类和接口,它的对象也与其他基于类的语言中的对象有所不同.在Javascript中,每个对象都是基于一个引用类型创建的,这个引用类型可以是原生类型 ...

  5. C# 获取汉字的拼音首字母

    /// <summary> /// 在指定的字符串列表CnStr中检索符合拼音索引字符串 /// </summary> /// <param name="CnS ...

  6. (转载)delphi文件流

    delphi文件流 [复制链接] 在Delphi中,所有流对象的基类为TStream类,其中定义了所有流的共同属性和方法. TStream类中定义的属性介绍如下: 1.Size: 此属性以字节返回流中 ...

  7. Use Sandcastle Help File Builder to generate help document

    http://shfb.codeplex.com/ Note: If the the help file contains the text "[Missing <param> ...

  8. IOS键盘样式风格有关设置

    一.键盘风格 UIKit框架支持8种风格键盘. typedef  enum  { UIKeyboardTypeDefault,                 // 默认键盘:支持所有字符 UIKey ...

  9. XCODE快捷键和功能汇总篇(不断更新)

    快捷键 command+b(build) 编译 command+r(run) 运行编译后程序鼠标放在代码元素上,按command然后单击,可以看到元素的属性

  10. 问题 K: 【USACO2012Feb】植草 {Bronze题2}

    按着矩形周长的思路,到当前边的时候,前一层的覆盖数乘以高度加入 ans 就行,然而真正的算法可能并不是这个..只能想到这个了 ; type node=record l,r,mid,sum,delta: ...