fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <tuple>
  4. #include <cstdint>
  5. #include <vector>
  6. #include <random>
  7. #include <algorithm>
  8.  
  9. typedef std::tuple<std::int64_t, std::int64_t, std::int64_t,std::uint64_t> Data;//x.y,r;
  10. typedef std::vector<Data> DType;
  11.  
  12. DType MakeVector(std::size_t N,unsigned int S,std::int64_t Min=0,std::int64_t Max=32) {
  13. std::minstd_rand mr(S);
  14. std::uniform_int_distribution<std::int64_t> UI(Min, Max);
  15. std::uniform_int_distribution<std::int64_t> UIR(1, 13);
  16. DType D;
  17.  
  18. for (std::size_t i = 0; i < N; i++) {
  19. D.push_back({ UI(mr), UI(mr), UIR(mr), 0 });
  20. }
  21.  
  22. return D;
  23. }
  24.  
  25. bool Conflict(const Data& A, const Data& B) {
  26. std::int64_t X = std::abs(std::get<0>(B) - std::get<0>(A));
  27. std::int64_t Y = std::abs(std::get<1>(B) - std::get<1>(A));
  28. std::int64_t R = std::abs(std::get<2>(B) +std::get<2>(A));
  29. return std::hypot(X, Y) <= R;
  30. }
  31.  
  32.  
  33. std::uint64_t MakeHoge(DType& D) {
  34.  
  35. std::uint64_t C = 0;
  36. std::uint64_t R = 0;
  37. for (std::size_t i = 0; i < D.size(); i++) {
  38. for (std::size_t j = 0; j < D.size(); j++) {
  39. if (i == j)continue;
  40. std::int64_t X = std::abs(std::get<0>(D[j]) - std::get<0>(D[i]));
  41. std::int64_t Y = std::abs(std::get<1>(D[j]) - std::get<1>(D[i]));
  42. std::int64_t R = std::abs(std::get<2>(D[j]) + std::get<2>(D[i]));
  43. //if (X*X+Y*Y <= R*R) { C++; }
  44. if (std::hypot(X, Y) <= R) { C++; }
  45. }
  46. R = std::max(R, C);
  47. std::get<3>(D[i]) = C;
  48. C = 0;
  49. }
  50.  
  51. return R;
  52. }
  53.  
  54. bool Show(const DType& D, const std::uint64_t N) {
  55. std::cout << "MaxCross:" << N <<"count" <<std::endl;
  56. for (auto& o : D) {
  57. std::cout << "X:" << std::get<0>(o) << " Y=" << std::get<1>(o) << " R=" << std::get<2>(o) << " Hit:" << std::get<3>(o)<< std::endl;
  58. }
  59. return true;
  60. }
  61.  
  62. int main() {
  63.  
  64. std::uint64_t R = 0;
  65. DType D;
  66.  
  67. D = MakeVector(12, 1, 0, 32);
  68.  
  69. R = MakeHoge(D);
  70.  
  71. Show(D, R);
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0s 4332KB
stdin
Standard input is empty
stdout
MaxCross:8count
X:0 Y=2 R=8 Hit:0
X:29 Y=31 R=3 Hit:4
X:16 Y=13 R=4 Hit:2
X:24 Y=2 R=8 Hit:2
X:19 Y=26 R=8 Hit:5
X:16 Y=28 R=13 Hit:8
X:23 Y=31 R=4 Hit:6
X:14 Y=29 R=9 Hit:4
X:29 Y=31 R=3 Hit:4
X:28 Y=29 R=4 Hit:5
X:30 Y=13 R=5 Hit:2
X:16 Y=13 R=11 Hit:6