Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct line {
- int k, b;
- bool x = false;
- long long c = 0;
- };
- int n;
- vector<line> lines;
- vector<pair<int, int>> p;
- bool Is3PointsOnLine(pair<float, float> p1, pair<float, float> p2, pair<float, float> p3) {
- if ((p2.first - p1.first) != 0 && (p2.second - p1.second) != 0) {
- return ((p3.first - p1.first) / (p2.first - p1.first) == (p3.second - p1.second) / (p2.second - p1.second));
- }
- else {
- //прямая вида x = a
- 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))
- return true; //fix me
- else
- return false;
- }
- }
- //лежит ли точка на прямой
- bool PointIsOnLine(line l, int x, int y) {
- if (!l.x) {
- if (y == ((l.k * x) + l.b))
- return true;
- }
- else {
- if (x == l.b)
- return true;
- }
- return false;
- }
- //составляем уравнение прямой
- line f(pair<int, int> c1, pair<int, int> c2) {
- int x1 = c1.first;
- int y1 = c1.second;
- int x2 = c2.first;
- int y2 = c2.second;
- line ans;
- if (x2 != x1) {
- ans.k = (y2 - y1) / (x2 - x1);//fix
- ans.b = -(x1 * y2 - x1 * y1 - x2 * y1 + x1 * y1) / (x2 - x1);
- ans.x = false;
- ans.c = 0;
- }
- else {
- ans.k = 0;
- ans.b = x1;
- ans.x = true;
- ans.c = 0;
- }
- return ans;
- }
- int a() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (j != i) {
- for (int k = 0; k < n; k++) {
- if ((k != i) && (k != j) && (Is3PointsOnLine(p[i], p[j], p[k]))) {
- lines.push_back(f(p[i], p[j]));
- return 0;
- }
- }
- }
- }
- }
- }
- int main() {
- cin >> n;
- p.resize(n);
- vector<int> not_used;
- for (int i = 0; i < n; i++)
- cin >> p[i].first >> p[i].second;
- if (n < 5) {
- cout << "yes";
- return 0;
- }
- else {
- //ищем первую прямую
- a();
- if (lines.size() == 0) {
- cout << "no";
- return 0;
- }
- pair<int, int> e = { -8,-8 };
- for (int i = 0; i < n; i++) {
- if (PointIsOnLine(lines[0], p[i].first, p[i].second)) {
- lines[0].c++;
- }
- else if (e.first == -8) {
- e.first = i;
- }
- else if (e.second == -8) {
- e.second = i;
- lines.push_back(f(p[e.first], p[e.second]));
- lines[1].c = 2;
- e = { -5,-5 };
- }
- else if (PointIsOnLine(lines[1], p[i].first, p[i].second)) {
- lines[1].c++;
- }
- else {
- cout << "no";
- return 0;
- }
- }
- cout << "yes";
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement