fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <vector>
  4. #include <random>
  5. #include <cstdint>
  6. #include <cmath>
  7. #include <algorithm>
  8.  
  9. typedef std::tuple<std::uintmax_t, std::uintmax_t > Point;
  10. typedef std::vector<Point> PType;
  11. typedef std::vector<std::vector<char>> MType;
  12.  
  13. MType MakeMap(const PType& P, std::uintmax_t W, std::uintmax_t H) {
  14. MType R(H);
  15. std::uintmax_t i = 0;
  16. for (auto& o : R) {
  17. o.resize(W,' ');
  18. }
  19.  
  20. for (auto& o : P) {
  21. R[std::get<1>(o)][std::get<0>(o)] = '#';
  22. }
  23.  
  24. return R;
  25. }
  26.  
  27. bool Show(const PType& P,std::uintmax_t W,std::uintmax_t H) {
  28. MType M = MakeMap(P, W, H);
  29. std::uintmax_t i = 0;
  30. for (auto oo : M) {
  31. std::cout <<i++<<'\t' << '*';
  32. for (auto o : oo) {
  33. std::cout << o;
  34. }
  35. std::cout << '*';
  36. std::cout << std::endl;
  37. }
  38.  
  39. return true;
  40. }
  41.  
  42. PType MakeRandomPoint(const std::uintmax_t& W, const std::uintmax_t& H, const std::uint64_t& Lim,const unsigned int& S = 0) {
  43.  
  44. //std::uint64_t Lim = 5;
  45. std::uint64_t L = (W + H)*2;
  46. std::mt19937 mt(S);
  47. std::uniform_int_distribution<std::uintmax_t> XD(0, std::max<std::intmax_t>(0,(static_cast<std::intmax_t>(W)-1)));
  48. std::uniform_int_distribution<std::uintmax_t> YD(0, std::max<std::intmax_t>(0,(static_cast<std::intmax_t>(H)-1)));
  49.  
  50. PType R;
  51.  
  52. for (std::uintmax_t i = 0; i < L; i++) {
  53. std::uintmax_t X = XD(mt);
  54. std::uintmax_t Y = YD(mt);
  55.  
  56. //double ML = Lim*Lim+1;
  57. double ML = Lim+1;
  58. double H = 0;
  59. for (std::size_t i = 0; i < R.size(); i++) {
  60. 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);
  61. ML = std::min<double>(H, ML);
  62. }
  63. if ( ((std::intmax_t)ML >= Lim)) { R.push_back({ X,Y }); }
  64. }
  65.  
  66. return R;
  67. }
  68.  
  69. PType SetWall(const std::uintmax_t& W,const std::uintmax_t& H,const PType& P,const std::uintmax_t Lim = 5) {
  70.  
  71. PType R = P;
  72. bool F = true;
  73. for (std::uintmax_t Y = 0; Y < H; Y++) {
  74. for (std::uintmax_t X = 0; X < W; X++) {
  75. //double ML = Lim*Lim+1;
  76. double ML = Lim+1;
  77. for (std::size_t i = 0; i < R.size(); i++) {
  78. double PX = static_cast<std::intmax_t>(X) - static_cast<std::intmax_t>(std::get<0>(R[i]));
  79. double PY = static_cast<std::intmax_t>(Y) - static_cast<std::intmax_t>(std::get<1>(R[i]));
  80. double H = std::hypot(PX, PY);
  81. ML = std::min<double>(H, ML);
  82. }
  83.  
  84. if (ML > 2) {
  85. if ((ML <= Lim)) {
  86. R.push_back({ X,Y });
  87. F = false;
  88. }
  89. }
  90.  
  91. }
  92. }
  93. //Show(R, W, H);
  94. return (!F) ? SetWall(W, H, R, Lim) : R;
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. PType MakeAnother(std::size_t W, std::size_t H, bool F = true) {
  102. MType M = MakeMap({}, W, H);
  103. PType P;
  104. int V = F ? 0 : 1;
  105. for (std::size_t i = 0; i < H; i++) {
  106. for (std::size_t j = ((i+V)%2);j < W; j+=2) {
  107. P.push_back({j,i});
  108. }
  109. }
  110. return P;
  111. }
  112.  
  113. int main() {
  114.  
  115.  
  116. PType P;
  117. std::uintmax_t W = 15;
  118. std::uintmax_t H = 15;
  119. std::uintmax_t Lim = 5;
  120. unsigned int Seed = 0;
  121.  
  122. std::random_device rd;
  123.  
  124.  
  125. for (std::size_t i = 0; i < 16; i++) {
  126. P = MakeRandomPoint(W, H, Lim, rd());
  127.  
  128. //Show(P, W, H);
  129.  
  130.  
  131.  
  132.  
  133. P = SetWall(W, H, P, Lim);
  134.  
  135. Show(P, W, H);
  136.  
  137. std::cout << std::endl;
  138. }
  139.  
  140. return 0;
  141. }
Success #stdin #stdout 0s 4448KB
stdin
Standard input is empty
stdout
0	*#  #    #  #  #*
1	*      #        *
2	*  #      #  #  *
3	*#   #  #      #*
4	*               *
5	* #    #   #  # *
6	*    #   #      *
7	*#          #  #*
8	*  #  #   #     *
9	*       #       *
10	*#  #      #  # *
11	*     #         *
12	*        #  #  #*
13	*  #   #        *
14	*#   #    #  #  *

0	*  #  #  #  #  #*
1	*#              *
2	*   #   #    #  *
3	* #       #    #*
4	*      #    #   *
5	*#  #    #    # *
6	*     #         *
7	*  #    #  #   #*
8	*#   #       #  *
9	*      #  #     *
10	* #         #  #*
11	*   #   #       *
12	*     #    #    *
13	* #      #      *
14	*   #  #      # *

0	*#  #  #    #  #*
1	*        #      *
2	*  #  #    #  # *
3	*#              *
4	*   #   #   #  #*
5	* #   #   #     *
6	*             # *
7	*#  #  #   #    *
8	*            #  *
9	* #  #   #     #*
10	*      #   #    *
11	*#           #  *
12	*   #   #      #*
13	* #   #     #   *
14	*        #    # *

0	*#  #   #  #    *
1	*     #        #*
2	* #      #  #   *
3	*      #      # *
4	*#  #     #     *
5	*     #        #*
6	* #     #   #   *
7	*   #     #   # *
8	*#    #         *
9	*  #       #   #*
10	*    #   #   #  *
11	*#     #        *
12	*  #      #   # *
13	*    #  #   #   *
14	*#             #*

0	*#  #  #  #    #*
1	*           #   *
2	* #     #     # *
3	*    #    #     *
4	*#     #     #  *
5	*  #       #   #*
6	*    #  #       *
7	*#        #  #  *
8	*  #  #        #*
9	*       #  #    *
10	*   #        #  *
11	*#    #  #     #*
12	*  #       #    *
13	*       #     # *
14	*#    #   #     *

0	*  #    #  #  # *
1	*#   #          *
2	*      #  #    #*
3	* #         #   *
4	*   #   #     # *
5	*#    #         *
6	*  #       #   #*
7	*    #  #    #  *
8	*#        #     *
9	*   #  #    #   *
10	*        #     #*
11	*  #  #    #    *
12	*#      #    #  *
13	*   #     #    #*
14	* #    #    #   *

0	*#  #  #  #   # *
1	*           #   *
2	* #  #  #      #*
3	*         #  #  *
4	*  #   #        *
5	*    #   #  #  #*
6	*#              *
7	*  #  #   #   # *
8	*       #   #   *
9	*#  #          #*
10	*     #  #   #  *
11	*  #       #    *
12	*#   #  #     # *
13	*         #     *
14	* #    #    #  #*

0	*#  #    #  #  #*
1	*      #        *
2	* #  #    #  #  *
3	*       #      #*
4	*#  #           *
5	*      #    #   *
6	* #      #    # *
7	*     #    #    *
8	*  #    #    #  *
9	*    #         #*
10	*#     #   #    *
11	*  #     #   #  *
12	*    #         #*
13	*#      #  #    *
14	*  #  #       # *

0	*#  #  #     #  *
1	*          #   #*
2	*    #  #       *
3	* #       #  #  *
4	*   #          #*
5	*#     #   #    *
6	*  #     #    # *
7	*    #      #   *
8	* #     #      #*
9	*   #     #  #  *
10	*#     #        *
11	*  #     #  #   *
12	*    #         #*
13	*#     #  #  #  *
14	*   #           *

0	*#  #   #  #  # *
1	*     #         *
2	*        #  #   *
3	* #  #        # *
4	*      #   #    *
5	*#  #        #  *
6	*     #   #    #*
7	* #     #   #   *
8	*   #         # *
9	*#    #  #      *
10	*  #       #   #*
11	*    #          *
12	*#      #    #  *
13	*  #  #   #    #*
14	*           #   *

0	*#  #  #  #  #  *
1	*              #*
2	*  #  #  #  #   *
3	*#            # *
4	*   #  #  #     *
5	* #         #  #*
6	*    #          *
7	*#      #  #  # *
8	*  #  #         *
9	*        #  #  #*
10	*#  #  #        *
11	*         #  #  *
12	* #   #        #*
13	*       #  #    *
14	*#   #       #  *

0	*#  #   #  #  # *
1	*     #         *
2	*  #     #  #   *
3	*#   #         #*
4	*       #  #    *
5	* #   #      #  *
6	*   #    #     #*
7	*      #    #   *
8	* #  #    #   # *
9	*       #       *
10	*#  #      #   #*
11	*      #     #  *
12	* #  #   #      *
13	*          #    *
14	*#  #  #      # *

0	*  #    #  #  # *
1	*#   #          *
2	*      #  #  #  *
3	* #             *
4	*   #   #  #    *
5	*#    #        #*
6	*  #     #  #   *
7	*      #      # *
8	*#              *
9	*    #  #  #   #*
10	* #          #  *
11	*   #  #  #     *
12	*           #   *
13	* #  #  #      #*
14	*         #  #  *

0	*#  #  #  #  #  *
1	*               *
2	* #  #     #    *
3	*       #      #*
4	*#  #     #  #  *
5	*     #         *
6	* #     #  #  # *
7	*   #           *
8	*     #  #   #  *
9	*#         #   #*
10	*  #   #        *
11	*    #   #  #   *
12	*#            # *
13	*  #  #   #     *
14	*       #    #  *

0	* #    #  #   # *
1	*   #       #   *
2	*#    #  #     #*
3	*  #       #    *
4	*      #     #  *
5	*#   #   #     #*
6	*  #       #    *
7	*     #       # *
8	*#  #   #   #   *
9	*              #*
10	* #  #    #  #  *
11	*      #        *
12	*  #     #  #  #*
13	*#   #          *
14	*      #  #  #  *

0	*  #  #  #   #  *
1	*#         #   #*
2	*   #  #        *
3	* #      #  #   *
4	*    #          *
5	*#     #  #   # *
6	*  #        #   *
7	*    #   #     #*
8	*#     #   #    *
9	*   #        #  *
10	* #   #  #     #*
11	*               *
12	*#  #       #   *
13	*      #  #   # *
14	* #  #          *