Advertisement
Hello_MMM

dsadads

Dec 16th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. struct line {
  10.     int k, b;
  11.     bool x = false;
  12.     long long c = 0;
  13. };
  14.  
  15. int n;
  16. vector<line> lines;
  17. vector<pair<int, int>> p;
  18.  
  19. bool Is3PointsOnLine(pair<float, float> p1, pair<float, float> p2, pair<float, float> p3) {
  20.     if ((p2.first - p1.first) != 0 && (p2.second - p1.second) != 0) {
  21.         return ((p3.first - p1.first) / (p2.first - p1.first) == (p3.second - p1.second) / (p2.second - p1.second));
  22.     }
  23.     else {
  24.         //прямая вида x = a
  25.         if ((p2.first == p1.first && p2.second == p1.second) || (p2.first == p1.first && p2.first == p3.first) || (p2.second == p1.second && p2.second == p3.second))
  26.             return true; //fix me
  27.         else
  28.             return false;
  29.     }
  30. }
  31.  
  32. //лежит ли точка на прямой
  33. bool PointIsOnLine(line l, int x, int y) {
  34.     if (!l.x) {
  35.         if (y == ((l.k * x) + l.b))
  36.             return true;
  37.     }
  38.     else {
  39.         if (x == l.b)
  40.             return true;
  41.     }
  42.     return false;
  43. }
  44.  
  45. //составляем уравнение прямой
  46. line f(pair<int, int> c1, pair<int, int> c2) {
  47.     int x1 = c1.first;
  48.     int y1 = c1.second;
  49.     int x2 = c2.first;
  50.     int y2 = c2.second;
  51.  
  52.     line ans;
  53.     if (x2 != x1) {
  54.         ans.k = (y2 - y1) / (x2 - x1);//fix
  55.         ans.b = -(x1 * y2 - x1 * y1 - x2 * y1 + x1 * y1) / (x2 - x1);
  56.         ans.x = false;
  57.         ans.c = 0;
  58.     }
  59.     else {
  60.         ans.k = 0;     
  61.         ans.b = x1;
  62.         ans.x = true;
  63.         ans.c = 0;
  64.     }
  65.  
  66.     return ans;
  67. }
  68.  
  69. int a() {
  70.     for (int i = 0; i < n; i++) {
  71.         for (int j = 0; j < n; j++) {
  72.             if (j != i) {
  73.                 for (int k = 0; k < n; k++) {
  74.                     if ((k != i) && (k != j) && (Is3PointsOnLine(p[i], p[j], p[k]))) {
  75.                         lines.push_back(f(p[i], p[j]));
  76.                         return 0;
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
  83.  
  84. int main() {   
  85.     cin >> n;
  86.     p.resize(n);
  87.  
  88.     vector<int> not_used;
  89.  
  90.     for (int i = 0; i < n; i++)
  91.         cin >> p[i].first >> p[i].second;
  92.    
  93.     if (n < 5) {
  94.         cout << "yes";
  95.         return 0;
  96.     }
  97.     else {
  98.         //ищем первую прямую
  99.         a();
  100.  
  101.         if (lines.size() == 0) {
  102.             cout << "no";
  103.             return 0;
  104.         }
  105.  
  106.         pair<int, int> e = { -8,-8 };              
  107.  
  108.         for (int i = 0; i < n; i++) {
  109.             if (PointIsOnLine(lines[0], p[i].first, p[i].second)) {
  110.                 lines[0].c++;
  111.             }
  112.             else if (e.first == -8) {
  113.                 e.first = i;
  114.             }
  115.             else if (e.second == -8) {
  116.                 e.second = i;
  117.                 lines.push_back(f(p[e.first], p[e.second]));
  118.                 lines[1].c = 2;
  119.                 e = { -5,-5 };
  120.             }
  121.             else if (PointIsOnLine(lines[1], p[i].first, p[i].second)) {
  122.                 lines[1].c++;
  123.             }
  124.             else {
  125.                 cout << "no";
  126.                 return 0;
  127.             }
  128.         }  
  129.        
  130.        
  131.         cout << "yes";
  132.         return 0;      
  133.     }  
  134.  
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement