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
| #include <bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned long long #define ls rt<<1 #define rs rt<<1|1 #define B1 131 #define B2 13331 #define M1 1000000007 #define M2 1000000009 #define eps 1e-8 #define MAXN 9e18 #define MS 200009 int n,m,k; struct point{ int x,y; }; struct node{ point c[2]; bool dir; }; int x,y,d; deque<node > Q;
vector<node > divide(int x, int y, int d){ vector<node > vc; node t; if(d == 0){ t.c[0] = t.c[1] = {x,y}; t.dir = 1; vc.push_back(t); return vc; } t.c[0] = {x, y-d}; t.c[1] = {x+d-1, y-1}; t.dir = 1; vc.push_back(t); t.c[0] = {x+d, y}; t.c[1] = {x+1, y+d-1}; t.dir = 0; vc.push_back(t); t.c[0] = {x-d+1, y+1}; t.c[1] = {x, y+d}; t.dir = 1; vc.push_back(t); t.c[0] = {x-1, y-d+1}; t.c[1] = {x-d, y}; t.dir = 0; vc.push_back(t); return vc; }
node merge(node t1, node t2){ node t; t.dir = t1.dir; if(t1.c[0].y > t2.c[0].y) t.c[0] = t1.c[0]; else t.c[0] = t2.c[0]; if(t1.c[1].y < t2.c[1].y) t.c[1] = t1.c[1]; else t.c[1] = t2.c[1]; return t; }
void cal(node t, vector<node > vc){ for(auto v:vc){ if(v.dir == t.dir){ if((t.dir == 1 && t.c[0].x-t.c[0].y == v.c[0].x-v.c[0].y) || (t.dir == 0 && t.c[0].x+t.c[0].y == v.c[0].x+v.c[0].y)){ node cc = merge(t, v); if(cc.c[1].y >= cc.c[0].y){ Q.push_back(cc); } } } else{ if(t.dir == 1){ int cy, cx = t.c[0].x+v.c[0].x+v.c[0].y-t.c[0].y; if(!(cx&1)){ cx /= 2; cy = cx-t.c[0].x+t.c[0].y; if(t.c[0].y <= cy && cy <= t.c[1].y && v.c[0].y <= cy && cy <= v.c[1].y){ node cc; cc.c[0] = cc.c[1] = {cx, cy}; cc.dir = 1; Q.push_back(cc); } } } else{ int cy, cx = t.c[0].x+v.c[0].x-v.c[0].y+t.c[0].y; if(!(cx&1)){ cx /= 2; cy = -cx+t.c[0].x+t.c[0].y; if(t.c[0].y <= cy && cy <= t.c[1].y && v.c[0].y <= cy && cy <= v.c[1].y){ node cc; cc.c[0] = cc.c[1] = {cx, cy}; cc.dir = 1; Q.push_back(cc); } } } } } }
void jdg(){ if(Q.empty()) cout << "impossible\n"; else if((int)Q.size() > 1) cout << "uncertain\n"; else{ node t = Q.front(); Q.pop_front(); if(t.c[0].x != t.c[1].x) cout << "uncertain\n"; else cout << t.c[0].x << " " << t.c[0].y << "\n"; } }
void init(){ vector<node > vc; cin >> x >> y >> d; vc = divide(x,y,d); for(auto v:vc) Q.push_back(v); }
void solve(){ cin >> n; init(); for(int i=2;i<=n;i++){ cin >> x >> y >> d; vector<node > vc = divide(x,y,d); for(int cnt = Q.size(); cnt; cnt--){ node t = Q.front(); Q.pop_front(); cal(t, vc); } } jdg(); }
int main(){ ios::sync_with_stdio(false); int ce = 1;
while(ce--){ solve(); } }
|