Advertisement
Hello_MMM

фывфыв

Dec 13th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct line {
  7.     int count = 0, k, b;
  8. };
  9.  
  10. bool cmp(pair<int, int> c1, pair<int, int> c2) {
  11.     return (c1.first == c2.first && c1.second == c2.second);
  12. }
  13.  
  14. bool PointIsOnLine(int m, int c, int x, int y) {
  15.     if (y == ((m * x) + c))
  16.         return true;
  17.     return false;
  18. }
  19.  
  20. pair<int, int> f(pair<int, int> c1, pair<int, int> c2) {
  21.     int x1 = c1.first;
  22.     int y1 = c1.second;
  23.     int x2 = c2.first;
  24.     int y2 = c2.second;
  25.  
  26.     int k = (y2 - y1) / (x2 - x1);
  27.     int b = -(x1 * y2 - x1 * y1 - x2 * y1 + x1 * y1) / (x2 - x1);
  28.  
  29.     pair<int, int> ans = { k, b };
  30.     return ans;
  31. }
  32.  
  33. int main() {
  34.     int n;
  35.     cin >> n;
  36.     vector<pair<int, int>> a(n);
  37.  
  38.     for (int i = 0; i < n; i++) {
  39.         cin >> a[i].first >> a[i].second;
  40.     }
  41.  
  42.     vector<line> lines;
  43.     pair<int, int> temp;
  44.     bool ln1 = false, ln2 = false;
  45.  
  46.     vector<int> not_in;
  47.  
  48.     pair<int, int> e = f(a[0], a[1]);
  49.     line smth; smth.b = e.first; smth.k = e.second; smth.count = 0;
  50.  
  51.     lines.push_back(smth);
  52.  
  53.     for (int i = 2; i < n; i++) {
  54.         bool flag = false;
  55.         if (lines.size() != 4) {
  56.             for (int j = 0; j < lines.size(); j++) {
  57.                 if (PointIsOnLine(lines[j].b, lines[j].k, a[i].first, a[i].second)) {
  58.                     flag = true;
  59.                     lines[j].count++;
  60.                 }
  61.             }
  62.             if (!flag) {
  63.                 not_in.push_back(i);
  64.                 if (not_in.size() >= 2) {
  65.                     e = f(a[not_in[not_in.size() - 2]], a[not_in[not_in.size() - 1]]);
  66.                     smth.b = e.first; smth.k = e.second; smth.count = 0;
  67.                     lines.push_back(smth);
  68.                 }
  69.             }
  70.         }
  71.         else {
  72.             cout << "no";
  73.             return 0;
  74.         }
  75.     }
  76.  
  77.     if (lines.size() <= 2) {
  78.         cout << "yes";
  79.     }
  80.     else if (lines.size() == 3 && (PointIsOnLine(lines[1].b, lines[1].k, a[0].first, a[0].second) || PointIsOnLine(lines[2].b, lines[2].k, a[0].first, a[0].second)) && (PointIsOnLine(lines[2].b, lines[2].k, a[1].first, a[1].second) || PointIsOnLine(lines[2].b, lines[2].k, a[1].first, a[1].second))) {
  81.         cout << "yes";
  82.     }
  83.     else {
  84.         cout << "no";
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement