标签:i++ span fine div return max sync map man
题目
https://vjudge.net/problem/Gym-101490G
题意
给出 n 个信标的二维坐标 ( X,Y ) 以及唯一接收器距离每个信标的曼哈顿距离 D ( ( x1, y1 ) 和 ( x2, y2 ) 的曼哈顿距离为 | x1 - x2 | + | y1 - y2 | ),问是否能确定接收器的位置。
题解
每个信标用曼哈顿距离可以构建出一个旋转 45° 的正方形,取随意一个正方形,用 ( x1, y1 ),( x2, y2 ) 来表示每条边构成边集,将该边集与每个正方形的边集求交集,看剩余的边集是否为唯一一个点。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define ull unsigned long long 4 #define met(a, b) memset(a, b, sizeof(a)) 5 #define rep(i, a, b) for(int i = a; i <= b; i++) 6 #define bep(i, a, b) for(int i = a; i >= b; i--) 7 #define lowbit(x) (x&(-x)) 8 #define MID (l + r) / 2 9 #define ls pos*2 10 #define rs pos*2+1 11 #define pb push_back 12 #define ios() ios::sync_with_stdio(0) 13 14 using namespace std; 15 16 const int maxn = 1e6 + 1010; 17 const int inf = 0x3f3f3f3f; 18 const ll INF = 0x3f3f3f3f3f3f3f3f; 19 const ll mod = 123456789; 20 21 struct NODE { 22 ll x, y, w; 23 }arr[1010]; 24 struct node { 25 ll x1, y1, x2, y2, k, b; 26 node () {} 27 node (ll t1, ll t2, ll t3, ll t4) { 28 x1 = t1, y1 = t2, x2 = t3, y2 = t4; 29 if(x1 == x2) k = 1; 30 else k = (y2 - y1) / (x2 - x1); 31 b = y1 - k*x1; 32 } 33 }t[5]; 34 35 map<pair<ll, ll>, ll> tran; 36 queue<node> que[2]; 37 ll tail; 38 39 void func(ll op) { 40 tran.clear(); 41 ll now = (op + 1) % 2; 42 while(!que[op].empty()) { 43 node p = que[op].front(); 44 que[op].pop(); 45 ll mp1 = p.x1 + p.y1*10000000; 46 ll mp2 = p.x2 + p.y2*10000000; 47 rep(k, 1, 4) { 48 ll x1 = inf, y1 = inf, x2 = inf, y2 = inf; 49 if(p.k == t[k].k) { 50 ll t1, tt1, t2, tt2; 51 if(p.x1 > t[k].x1) t1 = p.x1, tt1 = p.y1; 52 else t1 = t[k].x1, tt1 = t[k].y1; 53 if(p.x2 < t[k].x2) t2 = p.x2, tt2 = p.y2; 54 else t2 = t[k].x2, tt2 = t[k].y2; 55 if(p.b != t[k].b || t1 > t2) continue; 56 x1 = t1, y1 = tt1; 57 x2 = t2, y2 = tt2; 58 } 59 else { 60 double tt = 1.0 * (p.b - t[k].b) / (t[k].k - p.k); 61 if((ll)tt != tt || tt < p.x1 || tt > p.x2 || tt < t[k].x1 || tt > t[k].x2) continue; 62 x1 = x2 = tt; 63 y1 = y2 = p.k*x1 + p.b; 64 } 65 mp1 = x1 + y1*10000000; 66 mp2 = x2 + y2*10000000; 67 pair<ll, ll> pr = make_pair(mp1, mp2); 68 if(!tran[pr]) { 69 que[now].push((node){x1, y1, x2, y2}); 70 tran[pr] = 1; 71 } 72 } 73 } 74 } 75 int main() { 76 ios(); 77 ll n; 78 cin >> n; 79 rep(i, 1, n) cin >> arr[i].x >> arr[i].y >> arr[i].w; 80 que[1].push((node){arr[1].x - arr[1].w, arr[1].y, arr[1].x, arr[1].y + arr[1].w}); 81 que[1].push((node){arr[1].x, arr[1].y + arr[1].w, arr[1].x + arr[1].w, arr[1].y}); 82 que[1].push((node){arr[1].x, arr[1].y - arr[1].w, arr[1].x + arr[1].w, arr[1].y}); 83 que[1].push((node){arr[1].x - arr[1].w, arr[1].y, arr[1].x, arr[1].y - arr[1].w}); 84 rep(i, 1, n) { 85 t[1] = {arr[i].x - arr[i].w, arr[i].y, arr[i].x, arr[i].y + arr[i].w}; 86 t[2] = {arr[i].x, arr[i].y + arr[i].w, arr[i].x + arr[i].w, arr[i].y}; 87 t[3] = {arr[i].x, arr[i].y - arr[i].w, arr[i].x + arr[i].w, arr[i].y}; 88 t[4] = {arr[i].x - arr[i].w, arr[i].y, arr[i].x, arr[i].y - arr[i].w}; 89 func(i % 2); 90 } 91 ll tail = que[(n+1) % 2].size(); 92 if(tail == 0) cout << "impossible" << endl; 93 else { 94 node p = que[(n+1) % 2].front(); 95 if(tail > 1 || p.x1 != p.x2) cout << "uncertain" << endl; 96 else cout << p.x1 << ‘ ‘ << p.y1 << endl; 97 } 98 return 0; 99 }
Manhattan Positioning System --- Gym - 101490G
标签:i++ span fine div return max sync map man
原文地址:https://www.cnblogs.com/Stay-Online/p/12181919.html