#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;
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;
}
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 = (W + H)*2;
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;
double ML = Lim+1;
double H = 0;
for (std::size_t i = 0; i < R.size(); i++) {
H = std::hypot<std::intmax_t,std::intmax_t>(static_cast<std::intmax_t>(std::get<0>(R[i])) - X, static_cast<std::intmax_t>(std::get<1>(R[i])) - Y);
ML = std::min<double>(H, ML);
}
if ( ((std::intmax_t)ML >= 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;
double ML = Lim+1;
for (std::size_t i = 0; i < R.size(); i++) {
double PX = static_cast<std::intmax_t>(X) - static_cast<std::intmax_t>(std::get<0>(R[i]));
double PY = static_cast<std::intmax_t>(Y) - static_cast<std::intmax_t>(std::get<1>(R[i]));
double H = std::hypot(PX, PY);
ML = std::min<double>(H, ML);
}
if (ML > 2) {
if ((ML <= Lim)) {
R.push_back({ X,Y });
F = false;
}
}
}
}
//Show(R, W, H);
return (!F) ? SetWall(W, H, R, Lim) : R;
}
PType MakeAnother(std::size_t W, std::size_t H, bool F = true) {
MType M = MakeMap({}, W, H);
PType P;
int V = F ? 0 : 1;
for (std::size_t i = 0; i < H; i++) {
for (std::size_t j = ((i+V)%2);j < W; j+=2) {
P.push_back({j,i});
}
}
return P;
}
int main() {
PType P;
std::uintmax_t W = 15;
std::uintmax_t H = 15;
std::uintmax_t Lim = 5;
unsigned int Seed = 0;
std::random_device rd;
for (std::size_t i = 0; i < 16; i++) {
P = MakeRandomPoint(W, H, Lim, rd());
//Show(P, W, H);
P = SetWall(W, H, P, Lim);
Show(P, W, H);
std::cout << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxyYW5kb20+CiNpbmNsdWRlIDxjc3RkaW50PgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxhbGdvcml0aG0+Cgp0eXBlZGVmIHN0ZDo6dHVwbGU8c3RkOjp1aW50bWF4X3QsIHN0ZDo6dWludG1heF90ID4gUG9pbnQ7CnR5cGVkZWYgc3RkOjp2ZWN0b3I8UG9pbnQ+IFBUeXBlOwp0eXBlZGVmIHN0ZDo6dmVjdG9yPHN0ZDo6dmVjdG9yPGNoYXI+PiBNVHlwZTsKCk1UeXBlIE1ha2VNYXAoY29uc3QgUFR5cGUmIFAsIHN0ZDo6dWludG1heF90IFcsIHN0ZDo6dWludG1heF90IEgp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