#include <iostream>
#include <vector>
#include <random>
std::vector<std::pair<int, int>> Distance(const std::vector<std::pair<int, int>>& Tower, std::pair<int, int>& Ghost){
std::vector<std::pair<int, int>> ret;
int T = 0;
for (std::size_t i = 0; i < Tower.size(); i++){
T = std::abs(Ghost.first - Tower[i].first)+std::abs(Ghost.second-Tower[i].second);
if (ret.size() == 0){
ret.push_back(std::make_pair(static_cast<int>(i), T));
continue;
}
if (T == ret[0].second){
ret.push_back(std::make_pair(static_cast<int>(i), T));
continue;
}
if (T<ret[0].second){
ret.clear();
ret.push_back(std::make_pair(static_cast<int>(i), T));
continue;
}
}
return ret;
}
bool Show(char FB[8][8]){
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
if (FB[i][j] == 0) std::cout << '+';
else std::cout << FB[i][j];
}
std::cout << std::endl;
}
return true;
}
bool MakeHoge(const std::vector<std::pair<int, int>>& Tower, std::pair<int, int> Ghost){
char FB[8][8] = { 0, };
for (std::size_t i = 0; i < Tower.size(); i++){
FB[Tower[i].second][Tower[i].first] = 'A' + i;
}
FB[Ghost.second][Ghost.first] = '@';
Show(FB);
auto Res = Distance(Tower, Ghost);
std::cout << "out:";
for (auto& o : Res)std::cout << static_cast<char>('A' + o.first) << '@' << o.second << ' ';
std::cout << std::endl;
std::cout << std::endl;
return true;
}
int main(){
std::vector<std::pair<int, int>> vec{ { 2, 2 }, { 5, 2 }, { 2, 5 }, { 5, 5 } };
std::pair<int, int> Ghost{ 3, 3 };
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<> uid(0, 7);
MakeHoge(vec, Ghost);
for (int i = 0; i < 8; i++)MakeHoge({ { uid(mt), uid(mt) }, { uid(mt), uid(mt) }, { uid(mt), uid(mt) }, { uid(mt), uid(mt) } }, std::make_pair(uid(mt), uid(mt)));
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cmFuZG9tPgoKc3RkOjp2ZWN0b3I8c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