#pragma once
#pragma execution_character_set("utf-8")
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<int> SplitInt(const string& str, const string c)
{
vector<int> v;
string::size_type pos1, pos2;
pos1 = 0;
pos2 = str.find(c);
while (string::npos != pos2)
{
v.push_back(stoi(str.substr(pos1, pos2 - pos1)));
pos1 = pos2 + c.size();
pos2 = str.find(c, pos1);
}
if (pos1 != str.length())
{
v.push_back(stoi(str.substr(pos1)));
}
return v;
}
int _getsum1(int i, int j, int m, int n, vector<vector<int>> &vecTmp)
{
int sumP = 1;
queue<pair<int,int>> que;//用来存放位置是1的坐标
pair<int,int> peoplePos(i,j);
que.push(peoplePos);
vecTmp[i][j] = 0;
while (!que.empty())
{
int x = que.front().first;
int y = que.front().second;
for (int k1 = 0; k1 < 3; k1++)
{
int ny = y - 1 + k1;
for (int k2 = 0; k2 < 3; k2++)
{
int nx = x - 1 + k2;
if ((-1 < nx&&nx < n) && (-1 < ny&&ny < m) && (vecTmp[nx][ny] != 0))
{
peoplePos.first = nx;
peoplePos.second = ny;
que.push(peoplePos);
sumP += 1;
vecTmp[nx][ny] = 0;
}
}
}
que.pop();
}
return sumP;
}
int main()
{
string str;
getline(cin, str);
vector<int> vec = SplitInt(str, ",");
int M = vec.front();
int N = vec.back();
vector<vector<int>> vecV;
for (int i = 0; i < M; i++)
{
getline(cin, str);
vec = SplitInt(str, ",");
vecV.push_back(vec);
}
//----------------------------
vector<int> team;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
if (vecV[i][j] != 0)
{
int tmp = _getsum1(i, j, M, N, vecV);
team.push_back(tmp);
}
}
}
int P = team.size();
int Q = *max_element(team.begin(), team.end());
cout << P << "," << Q << endl;
system("pause");
return 0;
}
字节跳动2018.8.18世界杯
最新推荐文章于 2019-12-12 21:48:05 发布