poj 3620 Avoid The Lakes

原创 2012年03月25日 18:42:00

很简单的dfs

/*
Poj: 3620 Avoid The Lakes
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

#define MaxN 105

using namespace std;

int dirx[4] = {0, 0, -1, 1};
int diry[4] = {-1, 1, 0, 0};
bool map[MaxN][MaxN];
bool visited[MaxN][MaxN];;
int n, m, k;

bool check(int x, int y)
{
    if(x >= 1 && x <= n && y >= 1 && y <= m)
        return true;
    return false;
}

int dfs(int x, int y)
{
    int total = 1;
    for(int i = 0; i < 4; i++) {
        int tmpx = x + dirx[i];
        int tmpy = y + diry[i];
        if(check(tmpx, tmpy) && !visited[tmpx][tmpy] && map[tmpx][tmpy]) {
            visited[tmpx][tmpy] = true;
            total += dfs(tmpx, tmpy);
        }
    }
    return total;
}

int main()
{   
    //freopen("data.in", "rb", stdin);
    while(scanf("%d%d%d", &n, &m, &k) != EOF) {
        memset(map, false, sizeof(map));
        for(int i = 0; i < k; i++) {
            int a, b;
            scanf("%d%d", &a, &b);
            map[a][b] = true;
        }
        
        memset(visited, false, sizeof(visited));
    
        int res = 0;  
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                if(!visited[i][j] && map[i][j]) {
                    visited[i][j] = true;
                    res = max(dfs(i, j), res);
                }
            }
        }
        printf("%d\n", res);        
    }
    
    return 0;
}

相关文章推荐

poj 3620 Avoid The Lakes

Avoid The Lakes Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) ...

Avoid The Lakes(poj3620)

题目: Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated ...

POJ:3620 Avoid The Lakes(深搜DFS)

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: ...
  • zugofn
  • zugofn
  • 2016年07月29日 00:03
  • 149

POJ 3620 Avoid The Lakes dfs

Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu SubmitSta...

【poj3620】Avoid The Lakes

求一个坐标区域内,在给出的几点坐标中上下左右相邻的个数的最大值。#include #include #include using namespace std; const int N = 105; i...

poj3620Avoid The Lakes【dfs】

Language: Default Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Tota...

POJ 3620 Avoid The Lakes(DFS)

Avoid The Lakes Description Farmer John's farm was flooded in the most recent storm, a fact only...

HDU 1543:Avoid The Lakes 【深搜】

Avoid The Lakes Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) ...

Avoid The Lakes

Avoid The Lakes Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit inte...

POJ3620DFS

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8344  ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 3620 Avoid The Lakes
举报原因:
原因补充:

(最多只允许输入30个字)