Advertisement
Guest User

Yandex.Algorithm.2015 Online Round 2.2 Task A

a guest
Jun 13th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FINAL_OUT(x) {cout << x << '\n'; return 0;}
  5.  
  6. int sign(long long x)
  7. {
  8.     if (x > 0) return 1;
  9.     if (x < 0) return -1;
  10.     return 0;
  11. }
  12.  
  13. int vector_prod(pair<int,int> a, pair<int,int> b)
  14. {
  15.     return sign(a.first * 1LL * b.second - a.second * 1LL * b.first);
  16. }
  17.  
  18. int scalar_prod(pair<int,int> a, pair<int,int> b)
  19. {
  20.     return sign(a.first * 1LL * b.first + a.second * 1LL * b.second);
  21. }
  22.  
  23. int main()
  24. {
  25.     int xs,ys,xt,yt;
  26.     cin >> xs >> ys >> xt >> yt;
  27.  
  28.     pair<int,int> need(xt - xs, yt - ys);
  29.  
  30.     if (need == make_pair(0,0))
  31.         FINAL_OUT("YES");
  32.  
  33.     int n = 0;
  34.     cin >> n;
  35.     vector<pair<int,int> > a(n);
  36.     for(int i = 0; i < n; ++i)
  37.         cin >> a[i].first >> a[i].second;
  38.  
  39.     for(int i = 0; i < n; ++i)
  40.         for(int j = 0; j < n; ++j)
  41.             if (vector_prod(a[i], need) == 0)
  42.             {
  43.                 if (scalar_prod(a[i], need) > 0)
  44.                     FINAL_OUT("YES");
  45.             }
  46.             else
  47.             {
  48.                 if (vector_prod(a[i], a[j]) == vector_prod(a[i], need) && vector_prod(a[i], need) == vector_prod(need, a[j]))
  49.                     FINAL_OUT("YES");
  50.             }
  51.     FINAL_OUT("NO");
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement