Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1005;
  4.  
  5. const double eps = 1e-7 , pi = acos(-1.0);
  6. inline int dcmp(double x) {
  7. return (x > eps) - (x < -eps);
  8. }
  9.  
  10. struct Point {
  11. double x , y;
  12. Point (double x = 0 , double y = 0) : x(x) , y(y) {}
  13. void input() {
  14. scanf("%lf%lf",&x,&y);
  15. }
  16. bool operator < (const Point& R) const {
  17. if (dcmp(x - R.x) == 0)
  18. return dcmp(y - R.y) < 0;
  19. return dcmp(x - R.x) < 0;
  20. }
  21. bool operator == (const Point& R) const {
  22. return dcmp(x - R.x) == 0 && dcmp(y - R.y) == 0;
  23. }
  24. Point operator + (const Point& R) const {
  25. return Point(x + R.x , y + R.y);
  26. }
  27. Point operator - (const Point& R) const {
  28. return Point(x - R.x , y - R.y);
  29. }
  30. Point operator * (const double& R) const {
  31. return Point(x * R , y * R);
  32. }
  33. Point operator / (const double& R) const {
  34. return Point(x / R , y / R);
  35. }
  36. double operator ^ (const Point& R) const {
  37. return x * R.y - y * R.x;
  38. }
  39. double operator % (const Point& R) const {
  40. return x * R.x + y * R.y;
  41. }
  42. double len() {
  43. return sqrt(*this % *this);
  44. }
  45. double angle() {
  46. return atan2(y , x);
  47. }
  48. };
  49.  
  50. bool OnRay(Point P , Point a1 , Point a2) {
  51. double len = (P - a1).len();
  52. if (dcmp(len) == 0) return true;
  53. a1 = P - a1 , a2 = P - a2;
  54. return dcmp((a1 ^ a2) / len) == 0 && dcmp(a1 % (a2 - a1)) >= 0;
  55. }
  56. double GetLineIntersection(Point P , Point v , Point Q , Point w) {
  57. Point u = P - Q;
  58. return (w ^ u) / (v ^ w);
  59. }
  60. Point GetLineProjection(Point P , Point A , Point v) {
  61. return A + v * (v % (P - A) / (v % v));
  62. }
  63.  
  64. int n;
  65. Point p[N] , P , V;
  66. double r[N];
  67.  
  68. void work() {
  69. for (int i = 0 ; i < n ; ++ i) {
  70. scanf("%lf%lf%lf" , &p[i].x , &p[i].y , &r[i]);
  71. r[i] = -log10(r[i]);
  72. //cout << r[i] << endl;
  73. } p[n] = p[0];
  74.  
  75. P = Point(0 , 0);
  76. scanf("%lf%lf" , &V.x, &V.y);
  77. V = V / V.len();
  78.  
  79. double I = 0;
  80. int res = 0 , pre = -1;
  81. while (I <= 4) {
  82. ++ res;
  83.  
  84. bool point = 0;
  85. for (int i = 0 ; i < n ; ++ i) {
  86. if (OnRay(p[i] , P , P + V)) {
  87. point = 1;
  88. break;
  89. }
  90. }
  91. if (point) break;
  92. for (int i = 0 ; i < n ; ++ i) {
  93. if (i == pre) continue;
  94. Point w = p[i + 1] - p[i];
  95. if (dcmp(w ^ V) == 0) continue;
  96. double t0 = GetLineIntersection(P , V , p[i] , w);
  97. //cout << t0 << endl;
  98. if (dcmp(t0) <= 0) continue;
  99. double t1 = GetLineIntersection(p[i] , w , P , V);
  100. //cout << t1 << endl;
  101. if (dcmp(t1) <= 0 || dcmp(t1 - 1) >= 0) continue;
  102. //cout << "$$$" << endl;
  103. Point nxt = P + V * t0;
  104. I += r[i];
  105.  
  106. Point O = GetLineProjection(P , nxt , Point(-w.y , w.x));
  107.  
  108. V = O + O - P - nxt;
  109. V = V / V.len();
  110. P = nxt;
  111. //printf("%d : %f %f : %f %f | %f\n" , i , P.x , P.y , V.x , V.y , I);
  112. pre = i;
  113. break;
  114. }
  115. //break;
  116. }
  117. printf("%d\n" , res);
  118. }
  119.  
  120. int main() {
  121. while (~scanf("%d" , &n)) {
  122. work();
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement