• API
• FAQ
• Tools
• Archive
daily pastebin goal
36%
SHARE
TWEET

# Untitled

achulkov2 Jun 19th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2.
3. using namespace std;
4.
5. using C = int;
6. using M = long long;
7.
8. struct Vec {
9.     C x, y;
10.     explicit Vec(C x = 0, C y = 0): x(x), y(y) {}
11.     Vec operator + (const Vec &v) const {
12.         return Vec(x + v.x, y + v.y);
13.     }
14.     Vec operator - (const Vec &v) const {
15.         return Vec(x - v.x, y - v.y);
16.     }
17.     M operator * (const Vec& v) const {
18.         return static_cast<M>(x) * v.x + static_cast<M>(y) * v.y;
19.     }
20.     M operator % (const Vec &v) const {
21.         return static_cast<M>(x) * v.y - static_cast<M>(y) * v.x;
22.     }
23. };
24.
25. // Checking whether p, a, b are collinear
26. bool pol(Vec p, Vec a, Vec b) {
27.     return (p - a) % (b - a) == 0;
28. }
29.
30. // 2S_abc
31. M ds(Vec a, Vec b, Vec c) {
32.     return abs((b - a) % (c - a));
33. }
34.
35. bool lies_in_triangle(Vec a, Vec b, Vec c, Vec d) {
36.     bool inside = (ds(d, a, c) + ds(d, a, b) + ds(d, b, c) == ds(a, b, c));
37.     bool edge = (pol(d, a, c) || pol(d, a, b) || pol(d, b, c));
38.     return inside && (!edge);
39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top