Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define sz(x) ((int) (x).size())
  6. #define all(x) (x).begin(), (x).end()
  7. #define fi first
  8. #define se second
  9. #define mp make_pair
  10. #define pb push_back
  11. #define re return
  12. #define endl '\n'
  13.  
  14. using ll = long long;
  15. using ull = unsigned long long;
  16. using ii = pair<int, int>;
  17. using vi = vector<int>;
  18. using vii = vector<ii>;
  19. using ld = long double;
  20.  
  21. template <class T> T abs (T x) { re x > 0 ? x : -x; }
  22. template <class T> T sqr (T x) { re x * x; }
  23.  
  24. const ld pi = 4 * atan(1.);
  25. const int inf = 1e9 + 7;
  26. const int N = 3e5 + 17;
  27.  
  28. const double eps = 1e-9;
  29.  
  30. bool Eq (double x, double y) {
  31. return abs(x - y) < eps;
  32. }
  33.  
  34. bool Less (double x, double y) {
  35. return x < y && !Eq(x, y);
  36. }
  37.  
  38. struct point {
  39. double x, y;
  40. point () : x(), y() {}
  41. point (double _x, double _y) : x(_x), y(_y) {}
  42. point operator+(const point& a) const {
  43. return point(x + a.x, y + a.y);
  44. }
  45. point operator-(const point& a) const {
  46. return point(x - a.x, y - a.y);
  47. }
  48. point operator*(double k) const {
  49. return point(x * k, y * k);
  50. }
  51. point operator/(double k) const {
  52. return point(x / k, y / k);
  53. }
  54. double operator*(const point& a) const {
  55. return x * a.y - y * a.x;
  56. }
  57. double operator%(const point& a) const {
  58. return x * a.x + y * a.y;
  59. }
  60. bool operator==(const point& a) const {
  61. return Eq(x, a.x) && Eq(y, a.y);
  62. }
  63. bool operator<(const point& a) const {
  64. return Eq(x, a.x) ? Less(y, a.y) : x < a.x;
  65. }
  66. double sqrlen() const {
  67. return (*this) % (*this);
  68. }
  69. double len() const {
  70. return sqrt(sqrlen());
  71. }
  72. double sqrdist(const point& a) const {
  73. return (*this - a).sqrlen();
  74. }
  75. double dist(const point& a) const {
  76. return (*this - a).len();
  77. }
  78. point norm(double k = 1) const {
  79. return (*this) * (k / len());
  80. }
  81. point ort() const {
  82. return point(-y, x);
  83. }
  84. point rotate(double ang) {
  85. return (*this) * cos(ang) + ort() * sin(ang);
  86. }
  87. };
  88.  
  89. ostream& operator<<(ostream& out, const point& x) {
  90. cout << "(" << x.x << ", " << x.y << ")";
  91. re out;
  92. }
  93.  
  94. istream& operator>>(istream& in, point& x) {
  95. double a, b; cin >> a >> b;
  96. x = point(a, b);
  97. return in;
  98. }
  99.  
  100. double getang (point a, point b) {
  101. return atan2(a * b, a % b);
  102. }
  103.  
  104. bool online (point a, point b, point c) {
  105. return Eq(0, (a - b) * (a - c));
  106. }
  107.  
  108. bool onseg (point a, point b, point x) {
  109. if (!online(a, b, x)) re false;
  110. return Eq(0, (x - a) % (x - b));
  111. }
  112.  
  113. bool intersect (point A, point a, point B, point b, point& ans) {
  114. if (Eq(0, a * b)) return online(A, A + a, B);
  115. ans = B + b * (((A - B) * a) / (b * a));
  116. return true;
  117. }
  118.  
  119. bool intersect (point a, point b, point c, point d) {
  120. if (Eq(0, (b - a) * (d - c))) {
  121. if (!online(a, b, c)) re false;
  122. auto x = b - a;
  123. auto l1 = a % x, r1 = b % x;
  124. if (Less(r1, l1)) swap(l1, r1);
  125. auto l2 = c % x, r2 = d % x;
  126. if (Less(r2, l2)) swap(l2, r2);
  127. return !Less(min(r1, r2), max(l1, l2));
  128. }
  129. auto sgn = [](double x) { return Eq(0, x) ? 0 : (x > 0 ? 1 : -1); };
  130. if (sgn((a - c) * (a - d)) * sgn((b - c) * (b - d)) == 1) re false;
  131. if (sgn((c - a) * (c - b)) * sgn((d - a) * (d - b)) == 1) re false;
  132. re true;
  133. }
  134.  
  135. point project (point a, point v, point x) {
  136. return a + v.norm(((x - a) % v) / v.len());
  137. }
  138.  
  139. bool intersect (point a, point v, point o, double r, point& ans1, point& ans2) {
  140. auto h = project(a, v, o);
  141. double d = (h - o).sqrlen();
  142. if (Eq(d, sqr(r))) { ans1 = ans2 = h; re true; }
  143. if (Less(sqr(r), d)) re false;
  144. double cur = sqrt(sqr(r) - d);
  145. ans1 = h + v.norm(cur);
  146. ans2 = h - v.norm(cur);
  147. re true;
  148. }
  149.  
  150. bool inpoly (vector<point>& poly, point x) {
  151. double ang = 0;
  152. for (int i = 0; i < sz(poly); i++) {
  153. point l = poly[i], r = poly[(i + 1) % sz(poly)];
  154. if (online(l, r, x) && onseg(l, r, x)) re true;
  155. ang += getang(l - x, r - x);
  156. }
  157. return ang > 1;
  158. }
  159.  
  160. double area (vector<point>& poly) {
  161. double ans = 0;
  162. for (int i = 0; i < sz(poly) - 1; i++)
  163. ans += poly[i] * poly[i + 1];
  164. return abs(ans + poly.back() * poly[0]) / 2;
  165. }
  166.  
  167. vector<point> convex (vector<point>& a) {
  168. sort(all(a));
  169. vector<point> up, down;
  170. for (auto x : a) {
  171. while (sz(up) > 1 && !Less((up.back() - up[sz(up) - 2]) * (x - up.back()), 0)) up.pop_back();
  172. while (sz(down) > 1 && !Less(0, (down.back() - down[sz(down) - 2]) * (x - down.back()))) down.pop_back();
  173. up.pb(x), down.pb(x);
  174. }
  175. for (int i = 1; i < sz(down) - 1; i++) up.pb(down[i]);
  176. return up;
  177. }
  178.  
  179. int main() {
  180. ios::sync_with_stdio();
  181. cin.tie(0); cout.tie(0);
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement