九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/11025341
题目链接 :http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3982
Problem D
Radiation
Time Limit: 2 seconds
Nuclear power plants (NPP) are a blessing and curse of modern civilization. NPPs have some risks but still it is one of the cheapest ways to produce electricity in the developed world. In this problem we will discuss a situation related to two nuclear plants, which are not far away from each other.
|
Figure 1: Two Nuclear Power Plants. Houses at (81, 49) and (77,33) are at high risk from both the plants. |
We will describe the entire scenario in a flat land, so two-dimensional Cartesian coordinate system is used to denote each location. Letsassume that the coordinate of the two nuclear power plants are (ax, ay) and (bx, by). Houses that are located within distance R1 (inclusive) of the power plant at (ax, ay) are under high risk of radiation. Similarly, houses that are located within distance R2 (inclusive) of the power plant at (bx, by) are under high risk of radiation. So the authorities of power plant 1 and power plant 2 distribute special protective equipments to the houses that are within radius (inclusive) R1 and R2 of the respective power plants. As a result each of the houses that are endangered by both the plants actually receive two sets of equipments to protect their house, however only one set is enough for full protection. Houses that are outside the high-risk area are under low risk of radiation but they do not receive any protective equipment due to budget constraints. However, each owner of the houses that have two sets of protective equipments gives away one set of equipment to the owner of a house that has none. Still, some houses in the low-risk area remain un-protected. Given the location of the houses and the values of ax, ay, bx, by and possible values of R1 and R2 your job is to find out the number of houses that are without protective equipments for each pair of values of R1 and R2.
The input file contains at most 3 test cases. The description of each test case is given below:
A test case starts with a line containing a positive integer N (0 < N ≤ 200000) that denotes the number of houses that are under either low risk or high risk of radiation. Each of the next N lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20000) that denotes the coordinate of the i-thhouse. No two houses are at the same location. The next line contains five integers ax, ay, bx, by and q (0 ≤ ax, ay, bx, by ≤ 20000, 0 <q ≤ 20000). The meaning of ax, ay, bx and by are given in the problem statement. Here q denotes the total number of query. Each of the next q lines contains two integers, which denote the values of R1 and R2 (0 < R1, R2 ≤ 13000) respectively.
A line containing a single zero terminates input. This line should not be processed.
For each test case produce q+1 lines of output. The first line is the serial of output. For each query (given value of R1 and R2) determine how many houses in the low risk region remains without protective equipment. You may consider using faster IO as judge input file is large.
11 95 75 27 6 93 5 124 13 34 49 65 61 81 49 77 33 110 50 91 22 110 25 57 42 97 36 2 31 25 25 25 0 |
Case 1: 2 2
|
Note: First query in the sample input corresponds to Figure 1.
题意:
n
给定n个点的坐标
圆1的坐标 圆2的坐标 询问次数
圆1的半径 圆2的半径
问:对于每个询问,求出(不在圆上的点 - 在2圆重合 部分的点 ) //注意当答案<0 输出0
思路:首先对题意转化,可以看成是求 n - (在圆1上的点)-(在圆2上的点)
因为所有点是固定的,所以 (在圆1的点) => DIS( 点,圆心1) <= R1
只要求出所有满足上述不等式点的个数即可
把所有点按 (到圆心1的距离)小到大排序,存在p1数组中,再把p1中有相同dis的点去重后存在k1数组中,k1.num 就表示 距离<=k1.dis的点有 k1.num个
然后二分找到k1.dis <= R1 的最大的k1.num ,就是(在圆1上的点)
对圆2上的点相同操作
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <cstdio> #include <cctype> #include <queue> #include <stdlib.h> #include <cstdlib> #include <math.h> #include <set> #include <vector> #define inf 2000000 #define N 200200 using namespace std; struct node{ int x,y; int dis; bool operator<(const node& a)const {return a.dis>dis;} }p1[N],p2[N],r1,r2; struct kk{ int dis,num; }k1[N],k2[N]; int kn1,kn2; int R1,R2,sum1,sum2,n; int DIS(node a,node b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);} int erfen1(int l,int r,int d){ if(l==r-1 && k1[l].dis<=d && k1[r].dis>d ) return k1[l].num; int mid=(l+r)>>1; if(k1[mid].dis>d)return erfen1(l,mid,d); if(k1[mid].dis<d)return erfen1(mid,r,d); if(k1[mid].dis==d)return k1[mid].num; } int erfen2(int l,int r,int d){ if(l==r-1 && k2[l].dis<=d && k2[r].dis>d ) return k2[l].num; int mid=(l+r)>>1; if(k2[mid].dis>d)return erfen2(l,mid,d); if(k2[mid].dis<d)return erfen2(mid,r,d); if(k2[mid].dis==d)return k2[mid].num; } void quchong(){//p数组去重得到k数组 int i; for(i=1;i<=n;i++) { if(p1[i].dis==p1[i-1].dis)k1[kn1].num++; else { kn1++; k1[kn1].dis=p1[i].dis; k1[kn1].num=1+k1[kn1-1].num; } if(p2[i].dis==p2[i-1].dis)k2[kn2].num++; else { kn2++; k2[kn2].dis=p2[i].dis; k2[kn2].num=1+k2[kn2-1].num; } } } int main(){ int i,j,query,Cas=1; p1[0].dis=p2[0].dis=-1; //去重边界 while(scanf("%d",&n),n){ for(i=1;i<=n;i++)scanf("%d%d",&p1[i].x,&p1[i].y),p2[i]=p1[i]; scanf("%d %d %d %d %d",&r1.x,&r1.y,&r2.x,&r2.y,&query); for(i=1;i<=n;i++) p1[i].dis=DIS(p1[i],r1), p2[i].dis=DIS(p2[i],r2); sort(p1+1,p1+n+1); sort(p2+1,p2+n+1); kn1=kn2=0; quchong(); k1[0].dis=k2[0].dis=-1; //二分需要的边界条件 k1[0].num=k2[0].num=0; k1[kn1+1].dis=k2[kn2+1].dis=inf; //二分需要的边界条件 printf("Case %d:\n",Cas++); while(query--) { scanf("%d %d",&R1,&R2); sum1=erfen1(1,kn1,R1*R1); sum2=erfen2(1,kn2,R2*R2); int ans=n-sum1-sum2; if(ans<0)ans=0; printf("%d\n",ans); } } return 0; } /* 11 95 75 27 6 93 5 124 13 34 49 65 61 81 49 77 33 110 50 91 22 110 25 57 42 97 36 2 31 25 25 25 15 1 1 2 2 3 3 4 4 5 5 10 5 15 5 1 0 2 0 3 0 4 0 5 0 6 0 10 0 20000 20000 10 0 5 5 2 7 1 8 1 ans: 2 2 8 3 */