fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. using namespace std;
  5. struct jcv_point
  6. {
  7. float x, y;
  8. };
  9. int random(int min, int max) //range : [min, max]
  10. {
  11. static bool first = true;
  12. if (first)
  13. {
  14. srand(time(NULL)); //seeding for the first time only!
  15. first = false;
  16. }
  17. return min + rand() % ((max + 1) - min);
  18. }
  19.  
  20.  
  21. int main() {
  22. // your code goes here
  23.  
  24. int count = 8;
  25. jcv_point p1, p2, p3;
  26. p1.x = 325;
  27. p1.y = 239;
  28. p2.x = 431;
  29. p2.y = 448;
  30. p3.x = 640;
  31. p3.y = 685;
  32. float radius = 100;
  33. std::vector<jcv_point> grid;
  34. std::vector<int> rand_nums;
  35.  
  36. for (int i = 20; i < 1000; i++)
  37. {
  38. for (int j = 20; j < 1000; j++)
  39. {
  40. float x = (float)i;
  41. float y = (float)j;
  42.  
  43. float distance1 = sqrt(pow(p1.x - x, 2) + pow(p1.y - y, 2));
  44. float distance2 = sqrt(pow(p2.x - x, 2) + pow(p2.y - y, 2));
  45. float distance3 = sqrt(pow(p3.x - x, 2) + pow(p3.y - y, 2));
  46.  
  47. if (distance1 > radius && distance2 > radius && distance3 > radius)
  48. {
  49. jcv_point p;
  50. p.x = x;
  51. p.y = y;
  52. grid.push_back(p);
  53. int idx = random(0, grid.size());
  54. rand_nums.push_back(idx);
  55.  
  56. }
  57. }
  58. }
  59.  
  60. for (int i = 0; i < count; ++i)
  61. {
  62. int idx = random(0, grid.size());
  63. float x = grid[rand_nums[idx]].x;
  64. float y = grid[rand_nums[idx]].y;
  65. cout<<x <<","<<y<<endl;
  66. }
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0.03s 17448KB
stdin
Standard input is empty
stdout
280,40
123,372
666,389
309,631
253,869
823,232
543,207
26,398