度小满后台,第一题BSF 100和0.18,求第二题答案

// IT笔试.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <bitset>
#include <stack>

using namespace std;

int main()
{
	int n_x, n_y, n_n;
	cin >> n_x >> n_y >> n_n;
	int nTem_x, nTem_y;
	map<pair<int, int>, int> map_Luzhang;
	vector<vector<int>> vecvec_Map(1001, vector<int>(1001,0));
	while (n_n--)
	{
		cin >> nTem_x >> nTem_y;
		map_Luzhang[make_pair(nTem_x, nTem_y)] = 1;
	}
	int x[4] = { 1, -1, 0, 0 };
	int y[4] = { 0, 0, 1, -1 };
	deque<pair<int, int>> dep_Map;
	dep_Map.push_back(make_pair(0, 0));
	int nNum = 0;
	while (!dep_Map.empty())
	{
		int nLength = dep_Map.size();
		while (nLength--)
		{
			pair<int, int> cur_Node = dep_Map.front();
			dep_Map.pop_front();
			if (cur_Node.first != n_x || cur_Node.second != n_y)
			{
				for (size_t i = 0; i < 4; i++)
				{
					if (cur_Node.first + x[i] >= -500 && cur_Node.first + x[i] <= 500 && cur_Node.second + y[i] >= -500 && cur_Node.second + y[i] <= 500)
					{
						bool bLuzhang = map_Luzhang.find(make_pair(cur_Node.first + x[i], cur_Node.second + y[i])) == map_Luzhang.end();
						if ((vecvec_Map[cur_Node.first + x[i] + 500][cur_Node.second + y[i] + 500] != 1) && bLuzhang)
						{
							dep_Map.push_back(make_pair(cur_Node.first + x[i], cur_Node.second + y[i]));
							vecvec_Map[cur_Node.first + x[i] + 500][cur_Node.second + y[i] + 500] = 1;
						}
					}
				}
			}
			else
			{
				cout << nNum << endl;
				system("pause");
				return 0;
			}
		}
		++nNum;
	}

	system("pause");
    return 0;
}


#度小满##笔试题目#
全部评论
第二题55死活过不去
点赞 回复 分享
发布于 2019-09-15 20:53

相关推荐

永不遗忘:才这么点算什么拉黑,我初筛连着挂几十次了,最后还是能进面
点赞 评论 收藏
分享
04-11 21:31
四川大学 Java
野猪不是猪🐗:(ja)va学弟这招太狠了
点赞 评论 收藏
分享
评论
点赞
6
分享

创作者周榜

更多
牛客网
牛客企业服务