Quipex

839

Mar 6th, 2017
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct pt{long long x,y;};
  6. double mltpl(pt a, pt b){ //Векторное умножение А*В
  7.     return (a.x*b.y - b.x*a.y);
  8. }
  9. pt line(pt a, pt b){
  10.     pt c;
  11.     c.x = b.x - a.x;
  12.     c.y = b.y - a.y;
  13.     return c;
  14. }
  15. bool oneside(pt a, pt b, pt c, pt d){ //Лежат ли точки С и D на одной стороне от AB
  16.     pt ab, ac, ad;
  17.     ab = line(a, b);
  18.     ac = line(a, c);
  19.     ad = line(a, d);
  20.     if((mltpl(ac, ab)>0 && mltpl(ad, ab)>0)||
  21.        (mltpl(ac, ab)<0 && mltpl(ad, ab)<0)){
  22.         return true;
  23.     }
  24.     return false;
  25. }
  26. bool lay(pt a,pt b,pt c){ //Лежат ли 3 точки на 1 прямой
  27.     if((c.x - a.x)*(b.y - a.y)==(c.y - a.y)*(b.x - a.x))
  28.         return true;
  29.     return false;
  30. }
  31. bool intersect(int a,int b,int c,int d){ // Пересекаются ли AB и CD если лежат на 1 прямой
  32.     if (a > b) swap(a, b);
  33.     if (c > d) swap(c, d);
  34.     return max(a, c) <= min(b, d);
  35. }
  36. int main()
  37. {
  38.     pt a,b,c,d;
  39.     cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y;
  40.  
  41.     pt ab, ac, ad, cb, cd;
  42.     ab = line(a, b);
  43.     ac = line(a, c);
  44.     ad = line(a, d);
  45.     cb = line(c, b);
  46.     cd = line(c, d);
  47.     if (oneside(a, b, c, d)){
  48.         cout << "No";
  49.         return 0;
  50.     }
  51.     if (oneside(c, d, a, b)){
  52.         cout << "No";
  53.         return 0;
  54.     }
  55.     if ((lay(a,b,c) && lay(b,c,d)) == false){
  56.         cout << "Yes";
  57.         return 0;
  58.     }
  59.     if (intersect(a.x, b.x, c.x, d.x) && intersect(a.y, b.y, c.y, d.y)){
  60.         cout << "Yes";
  61.         return 0;
  62.     }
  63.     cout << "No";
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment