Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- using C = int;
- using M = long long;
- struct Vec {
- C x, y;
- explicit Vec(C x = 0, C y = 0): x(x), y(y) {}
- Vec operator + (const Vec &v) const {
- return Vec(x + v.x, y + v.y);
- }
- Vec operator - (const Vec &v) const {
- return Vec(x - v.x, y - v.y);
- }
- M operator * (const Vec& v) const {
- return static_cast<M>(x) * v.x + static_cast<M>(y) * v.y;
- }
- M operator % (const Vec &v) const {
- return static_cast<M>(x) * v.y - static_cast<M>(y) * v.x;
- }
- };
- // Checking whether p, a, b are collinear
- bool pol(Vec p, Vec a, Vec b) {
- return (p - a) % (b - a) == 0;
- }
- // 2S_abc
- M ds(Vec a, Vec b, Vec c) {
- return abs((b - a) % (c - a));
- }
- bool lies_in_triangle(Vec a, Vec b, Vec c, Vec d) {
- bool inside = (ds(d, a, c) + ds(d, a, b) + ds(d, b, c) == ds(a, b, c));
- bool edge = (pol(d, a, c) || pol(d, a, b) || pol(d, b, c));
- return inside && (!edge);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement