0
点赞
收藏
分享

微信扫一扫

河南省第八届省赛(最大岛屿)

心如止水_c736 2022-08-04 阅读 103


题目地址:​​点击打开链接​​

思路:水题,就是输入有点麻烦

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>

using namespace std;

int map1[510][510];
int m,n,t;
int dir[2][8] = {{-1,-1,-1,0,0,1,1,1},{-1,0,1,-1,1,-1,0,1}};
int sum = 0;

bool judge(int newx,int newy)
{
if(newx >= 0 && newx < m && newy >= 0 && newy < n)
return true;
return false;
}

void dfs(int x,int y)
{
int i;
sum++;
map1[x][y] = 0;
for(i=0; i<8; i++)
{
int newx = x + dir[0][i];
int newy = y + dir[1][i];
if(judge(newx,newy) && map1[newx][newy] == 1)
dfs(newx,newy);
}
}

int main()
{
char a;
int i,j;
int k;
while(scanf("%d%d%d",&m,&n,&t) != EOF)
{
getchar();
memset(map1,0,sizeof(map1));
for(i=0; i<m; i++)
{
k = 0;
while(true)
{
scanf("%c",&a);
if(a != ' ')
{
map1[i][k++] = a - '0';
}
if(k == n)
break;
}
getchar();
}
int sum1 = 0;
int max1 = 0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(map1[i][j] == 1)
{
sum1++;
sum = 0;
dfs(i,j);
max1 = max(sum,max1);
}
}
}
printf("%d %d\n",sum1,max1 * t);
}
return 0;
}




举报

相关推荐

0 条评论