Topic Link: http://acdream.info/problem?pid=1127 topic:
In mobile communication system, the establishment of communication network is mainly done by base station. The base station can be divided into main base station and sub-base station. The sub-base station and the various mobile users to connect, the sub-base station must be through the main base station to communicate with the outside world. The main base station can cover the range is a circular area, sub-base station and the main base station distance is less than the radius r to be covered by the main base station. Radius r is determined by the transmitting power of the main base station. A mobile communication network in a region that contains 2 main base stations and N sub-base stations. Their positions can correspond to an integer coordinate. If the sub-base station is overwritten by at least one primary base station, the sub-base station is active. Now the communication companies are debugging equipment, they constantly change the main base station transmit power, when the two main base station coverage radius is R1 and R2, need to know how many sub-base station is inactive. The key: The transformation of the coordinates, the sub-base station to the main base station 1 (X1,Y1) from the distance to the x-axis, the sub-base station to the main base station 2 (X2,Y2) of the distance into the y axis. The distance from the base station to the main base station 2 (X2,Y2) and the coverage radius of the main base station 2 are then discretized. Then sort the x-axis in descending order, and finally insert the y-axis into the tree array for maintenance and offline querying. Degree of responsibility:\ (O (M*LOGN) \)Code:
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int maxn = 2e5+100;const int mod = 1e9+7;stru CT node{int x, y; int id; BOOL operator < (const node &a) {return (x = = a.x && ID < a.id) | | (x > A.x); }}node[maxn];int num[maxn];int ans[maxn];map<int,int>mp;int sum[maxn];int k;void Update (int pos,int val) {//std: : cout << "k=" << k << ' \ n '; while (pos<=k) {sum[pos]+=val; pos + = (pos&-pos); }}int query (int pos) {int res = 0; while (POS) {res + = Sum[pos]; pos-= (Pos&-pos); } return res; Double distance (double x1,double y1,double x2,double y2) {return (double) sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));} int main (int argc, char const *argv[]) {int x1,x2,y1,y2; int n,m,x,y; while (std::cin >> x1 >> y1 >> x2 >> y2) {mp.clear (); k = 0; Std::cin >> N; for (int i=1;i<=n;i++) {std::cin >> x >> y; node[i].x = (int) DistancE (x,y,x1,y1); NODE[I].Y = (int) distance (x,y,x2,y2); Node[i].id =-I.; num[k++] = node[i].y; } std::cin >> m; for (int i=1;i<=m;i++) {std::cin >> node[i+n].x >> node[i+n].y; Node[i+n].id = i; num[k++] = node[i+n].y; } sort (num,num+k); K = Unique (num,num+k)-num; for (int i=0;i<k;i++) {Mp[num[i]] = i+1; } sort (node+1,node+n+m+1); memset (sum,0,sizeof (sum)); for (int i=1;i<=n+m;i++) {int pos = mp[node[i].y]; Std::cout << "now=" <<node[i].x<< "<< node[i].y <<" "<< node[i].id<<" "&L t;< pos << ' \ n '; if (Node[i].id < 0) {update (pos,1); } else if (node[i].id >= 1) {ans[node[i].id] = query (k)-Query (POS-1); }} for (int i=1;i<=m;i++) {std::cout << ans[i] << ' \ n '; }}//Cerr << "time Elapsed:" << 1.0 * Clock ()/clocks_per_sec << "s.\n"; Return 0;}
Acdream 1127 Base Station (offline query + tree-like array)