Advertisement
a53

Numara punctele

a53
Apr 14th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct punct{
  6. double x=0, y=0;
  7. };
  8. struct cerc{
  9. double x=0, y=0,r=0;
  10. };
  11.  
  12. vector<punct> v[100][100]; // matrice 100x100 ce va contintine distributia punctelor
  13. vector<cerc> q;
  14.  
  15. int main()
  16. {
  17. int n, m;
  18.  
  19. // citim cele n puncte:
  20. cin >> n;
  21. for(int i=0; i<n; i++)
  22. {
  23. punct p;
  24. double valoare;
  25. cin >> valoare;
  26. p.x = valoare;
  27. cin >> valoare;
  28. p.y = valoare;
  29. v[(int)p.x][(int)p.y].push_back(p); // inregistram punctul intr-o matrice de 100x100
  30. }
  31.  
  32. // cele m cercuri:
  33. cin >> m;
  34. for(int i=0; i<m; i++)
  35. {
  36. cerc c;
  37. double valoare;
  38. cin >> valoare;
  39. c.x = valoare;
  40. cin >> valoare;
  41. c.y = valoare;
  42. cin >> valoare;
  43. c.r = valoare;
  44. q.push_back(c);
  45. }
  46.  
  47. for(int k=0; k<m; k++) // pentru fiecare cerc in parte
  48. {
  49. int x1,y1,x2,y2;
  50. x1 = (int)(q[k].x-q[k].r);
  51. y1 = (int)(q[k].y-q[k].r);
  52. x2 = (int)(q[k].x+q[k].r);
  53. y2 = (int)(q[k].y+q[k].r);
  54. if (x1<0) x1=0;
  55. if (y1<0) y1=0;
  56. if (x2>99) x2=99;
  57. if (y2>99) y2=99;
  58. // voi calcula distanta pana la punctele din cele maxim 60x60 patrate
  59. // din jurul centrului cercului si nu pana la toate punctele
  60.  
  61. int contor=0;
  62. for(int i=x1; i<=x2; i++)
  63. for(int j=y1; j<=y2; j++)
  64. {
  65. // penru fiecare patratel ce se afla in patratul ce acopera cercul
  66. // vom calcula distantele pana la punctle din acesta. Daca sunt
  67. // mai mici decat raza, il numaram:
  68. for(int poz=0; poz<v[i][j].size(); poz++)
  69. {
  70. punct p = v[i][j][poz];
  71. double distx = p.x-q[k].x;
  72. double disty = p.y-q[k].y;
  73. if(distx*distx + disty*disty <= q[k].r*q[k].r)
  74. {
  75. contor++;
  76. }
  77. }
  78. }
  79. cout << contor << '\n';
  80. }
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement