kick start 2019 round A Parcels

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

vector> dis;
vector> office;
int max_dis;
vector matrix;

/**
 * 多源BFS
 * 和单源BFS完全一致的写法就是,同一层level的先到先得,O(m*n)复杂度
 * matrix:输入的0-1矩阵  office为所有的源节点的坐标数组
 **/
int multiple_BFS(vector& matrix,vector>& office) {
	queue> q;
	for(auto m : office) {
		q.push(m);
	}
	int level = 1;
	int res = 0;
	pair last;
	if(!q.empty()) {
		last = q.back();
	}
	else {
		res = matrix.size()-1 + matrix[0].size()-1;
		dis = vector>(matrix.size(),vector(matrix[0].size(),res));
		return res;
	}

	while(!q.empty()) {
		pair cur = q.front();
		q.pop();
		int x = cur.first;
		int y = cur.second;
		res = max(res,dis[x][y]);
		if(x-1>=0 && dis[x-1][y]==-1) {
			dis[x-1][y] = level;
			q.push(make_pair(x-1,y));
		}
		if(x+1=0 && dis[x][y-1]==-1) {
			dis[x][y-1] = level;
			q.push(make_pair(x,y-1));
		}
		if(y+1>& dis) {
	int m1 = INT_MIN, m2 = INT_MAX, m3 = INT_MIN, m4 = INT_MAX;

	for(int i=0;imax_dis) {
				m1 = max(m1,i+j);
				m2 = min(m2,i+j);
				m3 = max(m3,i-j);
				m4 = min(m4,i-j);
			}
		}
	}
	for(int i=0;i>& dis) {
	int l = 0,r = max_dis;
	while(l> T;

	for(int t=0;t> R >> C;
		office = vector>();
		dis = vector>(R,vector(C,-1));
		matrix = vector(R,string());

		for(int i=0;i> matrix[i];
			for(int j=0;j

你可能感兴趣的:(算法)