Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. typedef double TT;
  6. struct point
  7. {
  8. int x, y;
  9. point(){x = y = 0;}
  10. point(int a, int b){ x = a; y = b; }
  11.  
  12. TT operator* (const point &p) const{ // Dot
  13. return x * p.x + y * p.y;
  14. }
  15.  
  16. TT operator^ (const point &p) const{ // Cross
  17. return x * p.y - y * p.x;
  18. }
  19.  
  20. point operator+ (const point &p) const{
  21. return point(x + p.x, y + p.y);
  22. }
  23.  
  24. point operator- (const point &p) const{
  25. return point(x - p.x, y - p.y);
  26. }
  27.  
  28. point operator* (TT scale){
  29. return point(scale * x, scale * y);
  30. }
  31.  
  32. point operator/ (TT d){
  33. return point(1.0 * x / d, 1.0 * y / d);
  34. }
  35.  
  36. bool operator< (const point &p) const{
  37. if (x != p.x) return x < p.x;
  38. return y < p.y;
  39. }
  40.  
  41. bool operator== (const point &p) const{
  42. return x == p.x && y == p.y;
  43. }
  44.  
  45. bool operator!= (const point &p) const{
  46. return !(*this == p);
  47. }
  48.  
  49.  
  50. void scan(){ scanf("%d%d", &x, &y); }
  51.  
  52. double len(){ return hypot(x, y); }
  53.  
  54. double dist(const point &p) const{
  55. return (p - *this).len();
  56. }
  57. };
  58.  
  59. point rotate(point p, double theta){
  60. double rad = theta * acos(-1) / 180.0;
  61. return point(p.x * cos(rad) - p.y * sin(rad),
  62. p.x * sin(rad) + p.y * cos(rad));
  63. }
  64.  
  65. // Area of triangle
  66. double AreaOfTri(point a, point b, point c){
  67. point x = b - a;
  68. point y = c - a;
  69. return abs((x ^ y) / 2.0);
  70. }
  71.  
  72. // is three point collinear
  73. bool Collinear(point a, point b, point c){
  74. return AreaOfTri(a, b, c) == 0;
  75. }
  76.  
  77. const int Max = 5e5 + 5, Mod = 1e9 + 7;
  78.  
  79. point p[Max];
  80. int n, a[Max], r[Max];
  81. int LP[Max];
  82. vector<int> G[Max];
  83. bool vis[Max], OnStack[Max];
  84.  
  85. bool IsCycle(int u)
  86. {
  87. if (OnStack[u])
  88. return 1;
  89. if (vis[u])
  90. return 0;
  91. vis[u] = OnStack[u] = 1;
  92. for (auto v : G[u])
  93. if (IsCycle(v))
  94. return 1;
  95. OnStack[u] = 0;
  96. return 0;
  97. }
  98.  
  99. int lp(int u)
  100. {
  101. if (LP[u] != -1)
  102. return LP[u];
  103. LP[u] = 0;
  104. for (auto v : G[u])
  105. LP[u] = max(LP[u], lp(v));
  106. return LP[u];
  107. }
  108.  
  109. int main()
  110. {
  111. ios::sync_with_stdio(0);
  112. cin.tie(0); cout.tie(0);
  113.  
  114. memset(LP, -1, sizeof(LP));
  115.  
  116. cin >> n;
  117. for (int i = 0; i < n; i++){
  118. p[i].scan();
  119. cin >> a[i] >> r[i];
  120. }
  121.  
  122. for(int i=0;i<n;i++)
  123. for(int j=0;j<n;j++){
  124. point Line = p[i] - p[j];
  125.  
  126. point A = rotate(point(1e9, 0), a[j] - r[j]);
  127. point B = rotate(point(1e9, 0), a[j] + r[j]);
  128.  
  129. if( j != i && (A^Line) >= 0 && (Line^B) >= 0)
  130. G[j].push_back(i);
  131. }
  132.  
  133. for(int i=0;i<n;i++)
  134. if (!vis[i] && IsCycle(i)){
  135. cout << -1 << endl;
  136. return 0;
  137. }
  138.  
  139. for(int i=0;i<n;i++)
  140. lp(i);
  141.  
  142. vector<int> ans[n + 5];
  143. for (int i = 0; i < n; i++)
  144. ans[LP[i]].push_back(i);
  145.  
  146. for (int i = 0; i <= n; i++)
  147. for (auto j : ans[i])
  148. cout << j << ' ';
  149. cout << endl;
  150.  
  151. return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement