http://bailian.openjudge.cn/practice/2815?lang=en_US
题意:给你一个地图(二进制处理) 问有几个连通块,与最大连通块的面积。
题解:处理输入时,用四个if位运算判断。连通块模板处理。
#define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cstdlib> #include<cmath> #include<cstdio> #include<string> #include<stack> #include<ctime> #include<list> #include<set> #include<map> #include<queue> #include<vector> #include<sstream> #include<iostream> #include<functional> #include<algorithm> #include<memory.h> //#define INF 0x3f3f3f3f #define eps 1e-6 #define pi acos(-1.0) #define e exp(1.0) #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mp make_pair #define pb push_back #define mmm(a,b) memset(a,b,sizeof(a)) //std::ios::sync_with_stdio(false); using namespace std; typedef long long ll; typedef unsigned long long ull; void smain(); #define ONLINE_JUDGE int main() { ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock(); #endif smain(); #ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time); #endif return 0; } const int maxn = 1e4 + 100; const ll mod = 1e5 + 7; const ll INF = (100000)*(200000ll) + 1000; int n, m; int rooms[55][55]; int color[55][55]; int roomNum, mx; int area; void dfs(int i,int k) { if (color[i][k])return; area++; color[i][k] = roomNum; int x = rooms[i][k]; if ((x&1) == 0)dfs(i, k - 1); if ((x & 2) == 0)dfs(i-1, k); if ((x & 4) == 0)dfs(i, k + 1); if ((x & 8)==0)dfs(i+1, k); } void Run() { } void smain() { cin >> n >> m; rep(i,1,n) rep(j, 1, m) { cin>> rooms[i][j]; } mmm(color, 0); rep(i, 1, n) rep(j, 1, m) { if (!color[i][j]) { roomNum++; area = 0; dfs(i, j); mx = max(area, mx); } } cout << roomNum << endl; cout << mx << endl; }