字节跳动2018.8.18世界杯

这里写图片描述

#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;

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值