1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include<bits/stdc++.h>
using namespace std;
template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;} template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}
typedef long long LL; typedef vector<int> vi; typedef pair<int, int> pii; #define mp(x, y) make_pair(x, y) #define pb(x) emplace_back(x)
const int N = 2005;
int T, n, sid; LL x[N], y[N]; struct Segment{ LL x, y, dis; bool operator < (const Segment &A) const{ return dis > A.dis; } }s[N*N];
inline LL dis2(int a, int b){ return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]); }
int main(){ for(read(T); T; T--){ read(n); for(int i = 1; i <= n; i++) read(x[i], y[i]); sid = 0; vector<int> vis(n+5, 0); for(int i = 1; i <= n; i++) for(int j = 1; j < i; j++) s[++sid] = (Segment){j, i, dis2(i, j)}; sort(s+1, s+sid+1); for(int i = 1, bl = 1, sum = 0; sum <= n - 2; i++, bl++){ while(i <= sid && (vis[s[i].x] || vis[s[i].y])) i++; if(i == sid + 1) break; for(int k = i; k <= sid; k++){ if(s[k].dis != s[i].dis){ i = k; break; } if (vis[s[k].x] == 0 && vis[s[k].y] == 0) vis[s[k].x] = bl, vis[s[k].y] = bl, sum += 2; else if (vis[s[k].x] == 0 && vis[s[k].y] == bl) vis[s[k].y] = bl, ++sum; else if(vis[s[k].y] == 0 && vis[s[k].x] == bl) vis[s[k].y] = bl, ++sum; } } bool ok = false; for(int i = 2; i <= n; i++){ if(vis[i] == vis[1]){ ok = true; break; } } puts(ok ? "YES" : "NO"); } return 0; }
|