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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| #include <bits/stdc++.h> using namespace std; typedef long long ll; #define gc()(is==it?it=(is=in)+fread(in,1,Q,stdin),(is==it?EOF:*is++):*is++) const int Q=(1<<24)+1; char in[Q], *is=in, *it=in, c; void read(ll &n){ for(n = 0; (c = gc()) < '0' || c > '9';); for(;c <= '9' && c >= '0'; c = gc()) n = n * 10 + c - 48; }
void read(int &n){ for(n = 0; (c = gc()) < '0' || c > '9';); for(;c <= '9' && c >= '0'; c = gc()) n = n * 10 + c - 48; } pair <ll,ll> p[100005]; mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); ll rng(ll l,ll r) { uniform_int_distribution <ll> uni (l,r); return uni(mt); } map <pair<ll,ll> ,ll> mp,ans; ll n; struct Point{ ll x,y; Point(){ } Point (ll _x,ll _y):x(_x),y(_y) { } Point operator + (const Point &b) const { return Point(x+b.x,y+b.y); } ll operator ^ (const Point &b) const { return x*b.y-y*b.x; } Point operator -(const Point &b) const { return Point(x-b.x,y-b.y); } bool operator != (const Point &b) const { return x!=b.x||y!=b.y; } }P[60],fx,fff,QQ[60]; bool cmp(Point u,Point v) { ll du=u^fff,dv=v^fff; return du>dv; } void brute(){ ans.clear(); for (int i=1;i<=2*n;++i) { cin >> P[i].x >> P[i].y; } for (int i=2;i<=2*n;++i) { QQ[i]=P[i]-P[1]; } for (int i=2;i<=2*n;++i) { fx=QQ[i]; fff=Point(fx.y,-fx.x); sort(P+1,P+1+2*n,cmp); bool f=true; mp.clear(); for (int j=1;j<=2*n;++j) { mp[make_pair(P[j].x,P[j].y)]++; } for (int j=1;j<=2*n;++j) { if (!mp[make_pair(P[j].x,P[j].y)]) continue; mp[make_pair(P[j].x,P[j].y)]--; Point aft=P[j]+fx; if (mp[make_pair(P[j].x,P[j].y)]) j--; if (!mp[make_pair(aft.x,aft.y)]) { f=false; break; } mp[make_pair(aft.x,aft.y)]--; } if (f) { ans[make_pair(fx.x,fx.y)]++; ans[make_pair(-fx.x,-fx.y)]++; } } cout << ans.size() << endl; for (auto it:ans) { cout << it.first.first << " " << it.first.second << endl; } } void solve(){ mp.clear(); ans.clear(); for (int i=1;i<=2*n;++i) { cin >> p[i].first >> p[i].second; mp[p[i]]++; } ll e=rng(1,2*n); for (int i=1;i<=2*n;++i) { if (i==e) continue; ll dx=p[i].first-p[e].first,dy=p[i].second-p[e].second; bool f=true; for (int j=1;j<=2*n;++j) { bool ff=false; if (mp[make_pair(p[j].first+dx,p[j].second+dy)]) ff=true; if (mp[make_pair(p[j].first-dx,p[j].second-dy)]) ff=true; if (!ff) { f=false;break; } } if (f) { ans[make_pair(dx,dy)]++; ans[make_pair(-dx,-dy)]++; } } cout << ans.size() << endl; for (auto it:ans) { cout << it.first.first << " " << it.first.second << endl; } }
signed main(){ int T = 1; ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> T; while(T--) { cin >> n; if (n<=50) { brute(); }else { solve(); } } return 0; }
|