叉积法判断三点共线+重载运算符

https://ac.nowcoder.com/acm/contest/92687/G

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define lowbit(x) (x&-x)
using namespace std;
const double pi=acos(-1);
typedef pair<int,int> pii;

pii operator-(pii a, pii b)
{
    return {a.first - b.first, a.second - b.second};
}

int operator *(pii a, pii b)
{
    return a.first * b.second - a.second * b.first;
}


void solve(){
    int n;cin>>n;
    vector<pii> a(n+1);
    for(int i=1;i<=n;i++){
        int x,y;cin>>x>>y;
        a[i]={x,y};
    }
    bool ok=0;
    
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if((a[i]-a[j])*(a[i]-a[k])==0){
                    ok=1;break;
                }
            }
            if(ok) break;
        }
        if(ok) break;
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

posted on 2024-10-16 20:10  TaopiTTT  阅读(4)  评论(0编辑  收藏  举报