if(x1x2||y1y2||abs(y2-y1)==abs(x2-x1)) continue;
铭记少了abs(y2-y1)==abs(x2-x1)导致wa了
#include <bits/stdc++.h> using namespace std; #define x first #define y second # define rep(i,be,en) for(int i=be;i<=en;i++) # define pre(i,be,en) for(int i=be;i>=en;i--) #define ll long long #define endl "\n" #define LOCAL #define pb push_back typedef pair<ll, ll> PII; #define eb emplace_back #define sp(i) setprecision(i) const int N = 5e5 + 10, INF = 0x3f3f3f3f; const int eps=1e-8; int n; bool check(vector<PII>v,vector<PII>p) { for(int j=0;j<v.size();j++) { int x=v[j].x; int y=v[j].y; bool tt=1; for(int i=0;i<p.size();i++) { int x1=p[i].x; int y1=p[i].y; bool ok=false; if(x==x1) ok=true; if(y==y1) ok=true; if(abs(y-y1)==abs(x-x1)) ok=true; if(!ok) { tt=0; break; } } if(tt) return true; } return false; } void solve() { scanf("%d",&n); vector<PII>p(n); for(int i=0;i<n;i++) { scanf("%d%d",&p[i].x,&p[i].y); } if(n<=2) { cout<<"YES"<<endl; return; } vector<PII>v; bool ok=false; for(int i=1;i<n&&!ok;i++) { int x1=p[i].x; int x2=p[1].x; int y1=p[i].y; int y2=p[1].y; if(x1==x2||y1==y2||abs(y2-y1)==abs(x2-x1)) continue; ok=true; for(int k2=-1;k2<=1;k2++) { int b2=y2-k2*x2; v.push_back({x1,k2*x1+b2}); } //为2垂直 for(int k1=-1;k1<=1;k1++) { int b1=y1-k1*x1; v.push_back({x2,k1*x2+b1}); } for(int k1=-1;k1<=1;k1++) { for(int k2=-1;k2<=1;k2++) { if(k1==k2) continue; int b1=y1-k1*x1; int b2=y2-k2*x2; v.push_back({(b2-b1)/(k1-k2),k1*(b2-b1)/(k1-k2)+b1}); } } if(ok) break; } if(v.size()==0) { cout<<"YES"<<endl; return; } if(check(v,p)) { cout<<"YES"<<endl; }else { cout<<"NO"<<endl; } } signed main() { //#ifdef LOCAL //freopen("data.in.txt","r",stdin); //freopen("data.out.txt","w",stdout); //#endif int __ = 1; cin>>__; while (__--) { solve(); } return 0; }