題解:判斷點是否共線,是有數學公式的
#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;
}