fork(4) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const double eps = 1e-9;
  9.  
  10. double sqrDist(double x1, double y1, double x2, double y2) {
  11. return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  12. }
  13.  
  14. double dist(double x1, double y1, double x2, double y2) {
  15. return sqrt(sqrDist(x1, y1, x2, y2));
  16. }
  17.  
  18. const double PI = acos(-1.0);
  19.  
  20. int main() {
  21. int x0, y0, v, t;
  22.  
  23. scanf("%d%d%d%d", &x0, &y0, &v, &t);
  24.  
  25. double r0 = 1.0 * v * t;
  26.  
  27. int n;
  28. scanf("%d", &n);
  29.  
  30. vector<pair<double, int> > a;
  31.  
  32. for (int i = 0; i < n; i++) {
  33. int x, y, r;
  34. scanf("%d%d%d", &x, &y, &r);
  35. double d = sqrDist(x, y, x0, y0);
  36. if (d < 1.0 * r * r + eps) {
  37. printf("%.11f", 1.0);
  38. return 0;
  39. }
  40. d = sqrt(d);
  41. if (r + r0 < d - eps) {
  42. continue;
  43. }
  44.  
  45. double angL, angR, ang;
  46. double angM = atan2(y - y0, x - x0);
  47. if (angM < 0) {
  48. angM += 2 * PI;
  49. }
  50.  
  51. double tLen = sqrt(d * d - 1.0 * r * r);
  52. if (tLen < r0 + eps) {
  53. ang = asin(r / d);
  54. } else {
  55. ang = acos((d * d + r0 * r0 - 1.0 * r * r) / (2 * d * r0));
  56. }
  57.  
  58. angL = angM - ang;
  59. angR = angM + ang;
  60.  
  61. if (angL < 0) {
  62. a.push_back(make_pair(angL + 2 * PI, 1));
  63. a.push_back(make_pair(2 * PI, -1));
  64. a.push_back(make_pair(0.0, 1));
  65. a.push_back(make_pair(angR, -1));
  66. } else if (angR > 2 * PI) {
  67. a.push_back(make_pair(angL, 1));
  68. a.push_back(make_pair(2 * PI, -1));
  69. a.push_back(make_pair(0.0, 1));
  70. a.push_back(make_pair(angR - 2 * PI, -1));
  71. } else {
  72. a.push_back(make_pair(angL, 1));
  73. a.push_back(make_pair(angR, -1));
  74. }
  75. }
  76.  
  77. sort(a.begin(), a.end());
  78.  
  79. double last = 0;
  80. int c = 0;
  81. double ans = 0;
  82.  
  83. for (auto& p : a) {
  84. if (c > 0) {
  85. ans += p.first - last;
  86. }
  87. c += p.second;
  88. last = p.first;
  89. }
  90.  
  91. ans /= 2 * PI;
  92. printf("%.11f", ans);
  93.  
  94. return 0;
  95. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:23:39: error: 'scanf' was not declared in this scope
     scanf("%d%d%d%d", &x0, &y0, &v, &t);
                                       ^
prog.cpp:37:32: error: 'printf' was not declared in this scope
             printf("%.11f", 1.0);
                                ^
prog.cpp:83:16: error: ISO C++ forbids declaration of 'p' with no type [-fpermissive]
     for (auto& p : a) {
                ^
prog.cpp:83:20: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
     for (auto& p : a) {
                    ^
prog.cpp:85:22: error: request for member 'first' in 'p', which is of non-class type 'int'
             ans += p.first - last;
                      ^
prog.cpp:87:16: error: request for member 'second' in 'p', which is of non-class type 'int'
         c += p.second;
                ^
prog.cpp:88:18: error: request for member 'first' in 'p', which is of non-class type 'int'
         last = p.first;
                  ^
prog.cpp:92:24: error: 'printf' was not declared in this scope
     printf("%.11f", ans);
                        ^
stdout
Standard output is empty