zoukankan      html  css  js  c++  java
  • POJ 1164

    这道题的题目叙述着实唬人,感觉太多无关信息了

    不过说来惭愧,偷了个小懒去看了下别人怎么翻译的,这部分小痛苦直接跳过了

    简单DFS应用

    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <stack>
    #include <map>
    #include <set>
    using namespace std;
    
    const int maxn= 55;
    
    int m, n;
    int cas[maxn][maxn];
    bool vis[maxn][maxn];
    int step[4][2]= {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
    
    int DFS(int x, int y)
    {
    	if (x< 1 || x> m || y< 1 || y>n){
    		return 0;
    	}
    	int ret= 1;
    
    	for (int i= 0; i< 4; ++i){
    		if (cas[x][y] & (1<<i)){
    			continue;
    		}
    		int nx= x+step[i][0], ny= y+step[i][1];
    		if (!vis[nx][ny]){
    			vis[nx][ny]= 1;
    			ret+= DFS(x+step[i][0], y+step[i][1]);
    		}
    	}
    
    	return ret;
    }
    int main(int argc, char const *argv[])
    {
    	scanf("%d %d", &m, &n);
    	for (int i= 1; i<= m; ++i){
    		for (int j= 1; j<= n; ++j){
    			scanf("%d", cas[i]+j);
    		}
    	}
    
    	int ans=0, mx= 0;
    	memset(vis, 0, sizeof(vis));
    	for (int i= 1; i<= m; ++i){
    		for (int j= 1; j<= n; ++j){
    			if (!vis[i][j]){
    				++ans;
    				vis[i][j]= 1;
    				mx= max(mx, DFS(i, j));
    			}
    		}
    	}
    
    	printf("%d
    %d
    ", ans, mx);
    
    	return 0;
    }
    
  • 相关阅读:
    4.5计算机网络笔记
    3.29计算机网络笔记
    3.22计算机网络笔记
    3.15计算机网络笔记
    用int类型表示最大公倍数
    markdown入门
    learning by doing
    技术博客(初用markdown)。
    物联网PPT智能家居王思齐和陈由钧第10组
    第六次java作业
  • 原文地址:https://www.cnblogs.com/Idi0t-N3/p/14698219.html
Copyright © 2011-2022 走看看