Kuangyeye's Game

題目:Kuangyeye’s Game

題解:判斷點是否共線,是有數學公式的
在這裏插入圖片描述

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int inf = 0x7FFFFFFF;
const int N = 50005;

int A,B,C;
int X[N],Y[N];
map<P,int>vis;
map<P,int>::iterator it;

bool fun(int i){
    if(A*X[i]+B*Y[i]+C != 0) return true;
    else return false;
}
int main(){
    int n,len = 0;
    cin >> n;
    for(int i = 0;i < n;i++){
        int x,y;
        cin >> x >> y;
        vis[P(x,y)] = 1;
    }
    for(it = vis.begin();it != vis.end();it++){
        P t = it->first;
        X[++len] = t.first;
        Y[len] = t.second;
    }
    if(len == 1 || len == 2){
        cout<<"Yes\n";
        return 0;
    }
    A = Y[1]-Y[2];
    B = X[2]-X[1];
    C = X[1]*Y[2]-X[2]*Y[1];
    for(int i = 1;i <= len;i++){
        if(fun(i)){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}
發佈了335 篇原創文章 · 獲贊 25 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章