Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct Point {
  6. int x, y;
  7. };
  8.  
  9. int main() {
  10. // freopen("convex.in", "r", stdin);
  11. // freopen("convex.out", "w", stdout);
  12. int n;
  13. cin >> n;
  14. vector<Point> points(n, {0, 0});
  15. long double x1, y1, x2, y2;
  16.  
  17. for (int i = 0; i < n; i++) {
  18. cin >> points[i].x >> points[i].y;
  19. }
  20.  
  21. for (int j = 0; j < n - 1; ++j) {
  22. x1 = points[j].x;
  23. y1 = points[j].y;
  24. x2 = points[j + 1].x;
  25. y2 = points[j + 1].y;
  26. long double A = -(y1 - y2);
  27. long double B = -(x2 - x1);
  28. long double C = -(x1 * y2 - x2 * y1);
  29. long double znak = A * x1 + B * y1 + C;
  30. for (int i = 0; i < n; ++i) {
  31. x2 = points[i].x;
  32. y2 = points[i].y;
  33. if (!((znak > 0 && A * x2 + B * y2 + C > 0) ||
  34. (znak < 0 && A * x2 + B * y2 + C < 0))) {
  35. cout << "NO";
  36. return 0;
  37. }
  38. }
  39. }
  40.  
  41. cout << "YES";
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement