Test instructions: There is a m*m grid, coordinate [0...m-1,0...m-1] grid with two y-coordinates of the same hotel A and b, and n restaurants, hotel AB inside each has a restaurant, number 1, 2, other restaurant number 3-n, now you plan to open a new restaurant, you need to examine the possible location , a position p is a "good position" condition: when and only if for the existing restaurant Q, either p is closer to A than Q, or P is closer to B than Q, i.e. dist (P,A) < dist (q,a) or dist (P,B) < dist (q,b) ask "good position" number
#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <iostream > #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack& Gt #include <string> #include <map> #include <set> #define EPS 1e-6 #define LL Long long using namespace std; const int MAXN = 50000 + 50;const int MAXM = 60000 + 50;const int INF = 0x3f3f3f3f;int BORDERL[MAXM], BORDERR[MAXM], rest [MAXM]; int m, n, BEGX, EndX, level;//begx,endx record AB's horizontal axis void init () {memset (rest,-1, sizeof (rest)), Cin >> m >> n;int TX, Ty;cin >> tx >> ty; REST[TX] = ty; BEGX = tx;cin >> tx >> ty; REST[TX] = ty; EndX = tx;if (begx > EndX) Swap (BEGX, endx), level = ty;for (int i = 3; I <= n; i++) {cin >> tx >> ty;if (ty < level) Ty = 2*level-ty;if (rest[tx]! =-1) rest[tx] = min (Rest[tx], ty); else rest[tx] = ty;} }void solve () {int ans = 0;borderl[begx] = Borderl[endx] = LEVEL;BORDERR[BEGX] = Borderr[endx] = level;for (int i = begx + 1; i < EndX; i++) {if (rest[i]! =-1) {Borderl[i] = min (bo Rderl[i-1]+1, Rest[i]);} else {Borderl[i] = borderl[i-1] + 1;}} for (int i = endx-1; i > begx; i--) {if (rest[i]! =-1) {Borderr[i] = min (borderr[i+1]+1, rest[i]);} else {borderr[i] = BORDERR[I+1] + 1;}} for (int i = begx + 1; i < endx; i++) ans + = max (0, Min (borderl[i], borderr[i]), m)-max (Max (2*level-borderl[i), 2*le Vel-borderr[i]),-1)-1) cout << ans << endl;//for (int i = begx + 1; i < EndX; i++) cout << min (Border L[i], borderr[i]) << "" << Rest[i] << Endl;} int main () {//freopen ("Input.txt", "R", stdin); int t; Cin >> T;while (t--) {init (); Solve ();}}
Uvalive 4851 Restaurant (scanning method)