#include <iostream>
#include <tuple>
#include <vector>
#include <random>
#include <cstdint>
#include <cmath>
#include <algorithm>
typedef std::tuple<std::uintmax_t, std::uintmax_t > Point;
typedef std::vector<Point> PType;
typedef std::vector<std::vector<char>> MType;
PType MakeRandomPoint(const std::uintmax_t& W, const std::uintmax_t& H, const std::uint64_t& Lim,const unsigned int& S = 0) {
//std::uint64_t Lim = 5;
std::uint64_t L = std::sqrt(W * H);
std::mt19937 mt(S);
std::uniform_int_distribution<std::uintmax_t> XD(0, std::max<std::intmax_t>(0,(static_cast<std::intmax_t>(W)-1)));
std::uniform_int_distribution<std::uintmax_t> YD(0, std::max<std::intmax_t>(0,(static_cast<std::intmax_t>(H)-1)));
PType R;
for (std::uintmax_t i = 0; i < L; i++) {
std::uintmax_t X = XD(mt);
std::uintmax_t Y = YD(mt);
double ML = Lim*Lim+1;
for (auto o : R) {
double H = ((std::get<0>(o) - X) * (std::get<0>(o) - X)) + ((std::get<1>(o) - Y) * (std::get<1>(o) - Y));
//double H = std::hypot<std::intmax_t,std::intmax_t>(static_cast<std::intmax_t>(std::get<0>(o)) - X, static_cast<std::intmax_t>(std::get<1>(o)) - Y);
ML = std::min<double>(H, ML);
}
if ( ((std::intmax_t)ML >= Lim*Lim)) { R.push_back({ X,Y }); }
}
return R;
}
PType SetWall(const std::uintmax_t& W,const std::uintmax_t& H,const PType& P,const std::uintmax_t Lim = 5) {
PType R = P;
bool F = true;
for (std::uintmax_t Y = 0; Y < H; Y++) {
for (std::uintmax_t X = 0; X < W; X++) {
double ML = Lim*Lim+1;
for (auto& o : P) {
double H = ((std::get<0>(o) - X) * (std::get<0>(o) - X)) + ((std::get<1>(o) - Y) * (std::get<1>(o) - Y));
//double H = std::hypot(std::get<0>(o) - X, std::get<1>(o) - Y);
ML = std::min<double>(H, ML);
}
if ((ML <= (Lim*Lim)) && (ML >= 1)) {
if (ML >= (Lim*Lim) * 0.6) {
R.push_back({ X,Y });
F = false;
}
}
}
}
return (!F) ? SetWall(W, H, R, Lim) : R;
}
MType MakeMap(const PType& P, std::uintmax_t W, std::uintmax_t H) {
MType R(H);
std::uintmax_t i = 0;
for (auto& o : R) {
o.resize(W,' ');
}
for (auto& o : P) {
R[std::get<1>(o)][std::get<0>(o)] = '#';
}
return R;
}
bool Show(const PType& P,std::uintmax_t W,std::uintmax_t H) {
MType M = MakeMap(P, W, H);
std::uintmax_t i = 0;
for (auto oo : M) {
std::cout <<i++<<'\t' << '*';
for (auto o : oo) {
std::cout << o;
}
std::cout << '*';
std::cout << std::endl;
}
return true;
}
int main() {
/**/
{
double T = 0;
double T2 = 0;
double T3 = 0;
double T4 = 0;
}
/**/
PType P;
std::uintmax_t W = 15;
std::uintmax_t H = 15;
std::uintmax_t Lim = 5;
P = MakeRandomPoint(W, H, Lim);
Show(P, W, H);
//
std::cout << std::endl;
P=SetWall(W, H, P, Lim);
Show(P, W, H);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxyYW5kb20+CiNpbmNsdWRlIDxjc3RkaW50PgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxhbGdvcml0aG0+Cgp0eXBlZGVmIHN0ZDo6dHVwbGU8c3RkOjp1aW50bWF4X3QsIHN0ZDo6dWludG1heF90ID4gUG9pbnQ7CnR5cGVkZWYgc3RkOjp2ZWN0b3I8UG9pbnQ+IFBUeXBlOwp0eXBlZGVmIHN0ZDo6dmVjdG9yPHN0ZDo6dmVjdG9yPGNoYXI+PiBNVHlwZTsKClBUeXBlIE1ha2VSYW5kb21Qb2ludChjb25zdCBzdGQ6OnVpbnRtYXhfdCYgVywgY29uc3Qgc3RkOjp1aW50bWF4X3QmIEgsIGNvbnN0IHN0ZDo6dWludDY0X3QmIExpbSxjb25zdCB1bnNpZ25lZCBpbnQmIFMgPSAwKSB7CgoJLy9zdGQ6OnVpbnQ2NF90IExpbSA9IDU7CglzdGQ6On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