题目

找最大的一片湖的面积,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. android ListView_显示数据库数据

    xml <?xml version="1.0"?> -<LinearLayout tools:context=".MainActivity" ...

  2. 大数求模 sicily 1020

        Search

  3. wix xslt for adding node

    Using xslt to add new node item to wix source code. Original wix code: <Fragment> <Director ...

  4. 简明Python中的一个小错误

    最近在学Python,先看的是<Python基础教程>,后来经别人推荐,感觉网络上的<简明Python教程>也挺好的,在里面发现一个小错误. 网址如下:http://sebug ...

  5. JS去除数组中重复值的四种方法

    JS去除数组中重复值的四种方法 1 /// <summary>            o[this[i]] = "";  }      }       newArr.p ...

  6. jquery文字上下滚动的实现方法

    jquery实现文字上下滚动的方法. 代码: //上下滚动var textRoll=function(){$('#notice p:last').css({'height':'0px','opacit ...

  7. 在Centos7上安装漏洞扫描软件Nessus

    本文摘要:简单叙述了在Centos7上安装Nessus扫描器的过程   Nessus 是目前全世界最多人使用的系统漏洞扫描与分析软件,Nessus的用户界面是基于Web界面来访问Nessus漏洞扫描器 ...

  8. 22 高级SQL特性

    1.约束 为正确地进行关系数据库设计,需要一种方法来保证只在表中插入合法的数据.例如,如果Orders表存储订单信息,OrderItems表存储订单详细内容,应该保证Orderitems中引用的任何订 ...

  9. Nginx+uWSGI+Django原理

    Python的Web开发中,如果使用Django框架,那么较为成熟稳定的服务器架构一般是Nginx+uWSGI+Django.而为什么一定要三个结合在一起呢?直接使用Django的runserver来 ...

  10. Thread线程初探

    using System; using System.Threading; class Example { static void Main() { TimeSpan interval = , , ) ...