Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct line {
- int count = 0, k, b;
- };
- bool cmp(pair<int, int> c1, pair<int, int> c2) {
- return (c1.first == c2.first && c1.second == c2.second);
- }
- bool PointIsOnLine(int m, int c, int x, int y) {
- if (y == ((m * x) + c))
- return true;
- return false;
- }
- pair<int, int> 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;
- int k = (y2 - y1) / (x2 - x1);
- int b = -(x1 * y2 - x1 * y1 - x2 * y1 + x1 * y1) / (x2 - x1);
- pair<int, int> ans = { k, b };
- return ans;
- }
- int main() {
- int n;
- cin >> n;
- vector<pair<int, int>> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i].first >> a[i].second;
- }
- vector<line> lines;
- pair<int, int> temp;
- bool ln1 = false, ln2 = false;
- vector<int> not_in;
- pair<int, int> e = f(a[0], a[1]);
- line smth; smth.b = e.first; smth.k = e.second; smth.count = 0;
- lines.push_back(smth);
- for (int i = 2; i < n; i++) {
- bool flag = false;
- if (lines.size() != 4) {
- for (int j = 0; j < lines.size(); j++) {
- if (PointIsOnLine(lines[j].b, lines[j].k, a[i].first, a[i].second)) {
- flag = true;
- lines[j].count++;
- }
- }
- if (!flag) {
- not_in.push_back(i);
- if (not_in.size() >= 2) {
- e = f(a[not_in[not_in.size() - 2]], a[not_in[not_in.size() - 1]]);
- smth.b = e.first; smth.k = e.second; smth.count = 0;
- lines.push_back(smth);
- }
- }
- }
- else {
- cout << "no";
- return 0;
- }
- }
- if (lines.size() <= 2) {
- cout << "yes";
- }
- 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))) {
- cout << "yes";
- }
- else {
- cout << "no";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement