【魔方系列】最大色块
Time Limit: 1000ms
Case Time Limit: 30000ms
Memory Limit: 65536KB
64-bit integer IO format: lld
Java class name: Main
DreamFox有时候还原魔方玩腻了,就会想出一些新点子来玩转魔方。有一次灵感一来,哈,魔方拼字!于是弄来他收藏的12个精品魔方,迅速的拼出了他们宿舍号525,及其壮观华丽!
当然有时也想不到要拼什么好,于是就乱拼,弄出一些乱七八糟的东西。这时候DreamFox的好奇心又来了,这6个颜色哪个颜色连在一起的块数最多呢?比如那个照片上,肯定是黄色连在一起的颜色最大啦。一共有66块(应该没数错吧)。DreamFox现在想知道,每次他随机拼出的图案,最大的那个同颜色色块有多大。当然,他很懒,所以就麻烦你帮忙了~!
当然有时也想不到要拼什么好,于是就乱拼,弄出一些乱七八糟的东西。这时候DreamFox的好奇心又来了,这6个颜色哪个颜色连在一起的块数最多呢?比如那个照片上,肯定是黄色连在一起的颜色最大啦。一共有66块(应该没数错吧)。DreamFox现在想知道,每次他随机拼出的图案,最大的那个同颜色色块有多大。当然,他很懒,所以就麻烦你帮忙了~!
Input
第1行:魔方围成的行,列(m,n<=48)
第2行以后:m行n列的二维字符数组,表示魔方拼出的图案。R表示红色,O表示橙色,B表示蓝色,G表示绿色,W表示白色,Y表示黄色。
第2行以后:m行n列的二维字符数组,表示魔方拼出的图案。R表示红色,O表示橙色,B表示蓝色,G表示绿色,W表示白色,Y表示黄色。
Output
共1行:表示最大色块的面积(每小格面积为1,若一个块的上下左右四个方向有相同色块,说明相邻)
Sample Input
6 18
YYYYYYYYYYYYYYYYYY
YRRRRYYRRRRYYRRRRY
YRYYYYYYYYRYYRYYYY
YRRRRYYRRRRYYRRRRY
YYYYRYYRYYYYYYYYRY
YRRRRYYRRRRYYRRRRY
Sample Output
66 ///AC代码#include <iostream> #include <set> #include <map> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <iomanip> #include <cstring> #include <algorithm> #include <functional> #define PI acos(-1) #define eps 1e-8 #define inf 0x3f3f3f3f #define debug(x) cout<<"---"<<x<<"---"<<endl typedef long long ll; using namespace std; char str[55][55]; bool vis[55][55]; int dix[4] = {1, -1, 0, 0}; int diy[4] = {0, 0, 1, -1}; int sum, m, n; bool cango(int x, int y) { return x >= 0 && x < m && y >= 0 && y < n; } void dfs(int x, int y) { if (vis[x][y] == true) { return ; } vis[x][y] = true; sum++; for (int i = 0; i < 4; i++) { int _x = x + dix[i]; int _y = y + diy[i]; if (cango(_x, _y) && str[_x][_y] == str[x][y]) { dfs(_x, _y); } } } int main() { int ans = 0; cin >> m >> n; for (int i = 0; i < m; i++) { cin >> str[i]; } memset(vis, false, sizeof(vis)); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { sum = 0; dfs(i, j); ans = max(ans, sum); } } cout << ans << endl; return 0; }