度小满后台,第一题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; }
#度小满##笔试题目#