Advertisement
ekzolot

Untitled

Nov 17th, 2023
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. double mod(int x){
  4.     if (x<0){
  5.         x=-x;
  6.     }
  7.     return x;
  8. }
  9. int sign(int x){
  10.     if (x>0){
  11.         return 1;
  12.     }
  13.     if (x==0){
  14.         return 0;
  15.     }
  16.     return -1;
  17. }
  18. struct Point{
  19.     int x;
  20.     int y;
  21. };
  22. Point draw_vector(Point p, Point q){
  23.     return {q.x-p.x, q.y-p.y};
  24. }
  25. int cross_product(Point p, Point q){
  26.     return p.x*q.x+p.y*q.y;
  27. }
  28. int dot_product(Point p, Point q){
  29.     return p.x*q.y-p.y*q.x;
  30. }
  31. int main(){
  32.     Point a, o, b, p;
  33.     cin>>a.x>>a.y>>o.x>>o.y>>b.x>>b.y>>p.x>>p.y;
  34.     if (dot_product(draw_vector(o, a), draw_vector(o, p))==0){
  35.         if (cross_product(draw_vector(o, p), draw_vector(o, a))>=0){
  36.             cout<<"YES"<<"\n";
  37.             return 0;
  38.         }
  39.         cout<<"NO"<<"\n";
  40.         return 0;
  41.     }
  42.     if (dot_product(draw_vector(o, b), draw_vector(o, p))==0){
  43.         if (cross_product(draw_vector(o, p), draw_vector(o, b))>=0){
  44.             cout<<"YES"<<"\n";
  45.             return 0;
  46.         }
  47.         cout<<"NO"<<"\n";
  48.         return 0;
  49.     }
  50.     if (sign(dot_product(draw_vector(o, a), draw_vector(o, p)))==sign(dot_product(draw_vector(o, a), draw_vector(o, b)))){
  51.         if (sign(dot_product(draw_vector(o, b), draw_vector(o, p)))==sign(dot_product(draw_vector(o, b), draw_vector(o, a)))){
  52.             cout<<"YES"<<"\n";
  53.             return 0;
  54.         }
  55.     }
  56.     cout<<"NO"<<"\n";
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement