XMU 1612 刘备闯三国之桃园结义 【二分】

1612: 刘备闯三国之桃园结义

Time Limit: 1000 MS  Memory Limit: 128 MB
Submit: 181  Solved: 12
[Submit][Status][Web Board]

Description

 

        刘备(161年-223年6月10日),字玄德,东汉末年幽州涿郡涿县,西汉中山靖王刘胜的后代。刘备一生极具传奇色彩,早年颠沛流离、备尝艰辛最终却凭借自己的谋略终成一方霸主。那么在那个风云激荡的年代,刘备又是如何从一个卖草鞋的小人物一步一步成为蜀汉的开国皇帝呢?让我们一起拨开历史的迷雾,还原一个真实的刘备。

      刘备心怀大志,当然不甘于当一个卖草鞋的小贩,于是离家闯荡江湖。恰好遇到志同道合的关羽、张飞二人,三人准备在桃园结义。但是在谁当大哥的问题上,关张并不服刘备当老大,二人环顾四周,灵机一动,给刘备提出如下问题:

        当时的桃园游人摩肩接踵、然而春雨绵绵。桃园内有n个行人,和m个亭子,有些游客在亭子内躲雨,但也有一些行人在雨中漫步。关张表示:如果刘备能准确统计出有多少个人在雨中,那他们就认刘备当大哥。桃园可以看出二维平面坐标轴,行人为点,亭子为圆形。

        刘备微微一笑,左顾右盼、前瞻后顾,然而算得头昏脑胀。做为刘备身边的小弟,又到了你替老大分担忧愁的时候了。

 

Input

 第一行一个整数n(1<=n<=10^5),表示有n个行人

以下有n行,每行有n有两个整数x,y (0<=x,y<=10000),表示行人的坐标为(x,y)

接下来有一个整数m(1<=m<=20000),表示桃园中有m个亭子,亭子可以视为圆形。

以下m行,每行有3个整数x ,y ,r ,(0<=x,y<=10000, 1<=r<=100)表示亭子的中心坐标为(x,y),半径为r,亭子之间可以相交。

Output

 输出在雨中行人的个数。

如果行人在亭子的边缘位置,也记为在亭子内。

Sample Input

5
0 0
100 0
0 100
100 100
50 50
1
0 0 50

Sample Output

4

HINT

 

Source

[Submit][Status][Web Board]

题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1612

题目大意:

  图上有N个点,M个圆,圆可能相交,问N个点中不被任何圆覆盖到的点有多少个。

题目思路:

  【二分】

  首先将点按x坐标从小到大排序,再将圆按照x+r从小到大排序

  之后枚举每一个点,二分找到第一个x坐标包含到当前点x坐标的圆,之后开始往后判断,是否被圆覆盖。只要一被覆盖就break

  

  1 /****************************************************
  2      
  3     Author : Coolxxx
  4     Copyright 2017 by Coolxxx. All rights reserved.
  5     BLOG : http://blog.csdn.net/u010568270
  6      
  7 ****************************************************/
  8 #include<bits/stdc++.h>
  9 #pragma comment(linker,"/STACK:1024000000,1024000000")
 10 #define abs(a) ((a)>0?(a):(-(a)))
 11 #define lowbit(a) (a&(-a))
 12 #define sqr(a) ((a)*(a))
 13 #define mem(a,b) memset(a,b,sizeof(a))
 14 const double EPS=1e-8;
 15 const int J=10;
 16 const int MOD=100000007;
 17 const int MAX=0x7f7f7f7f;
 18 const double PI=3.14159265358979323;
 19 const int N=100004;
 20 const int M=20004;
 21 using namespace std;
 22 typedef long long LL;
 23 double anss;
 24 LL aans;
 25 int cas,cass;
 26 int n,m,lll,ans;
 27 bool in[N];
 28 struct Point
 29 {
 30     int x,y;
 31 }p[N];
 32 struct Circle
 33 {
 34     int x,y,r;
 35 }c[M];
 36 bool cmp1(Point a,Point b)
 37 {
 38     if(a.x!=b.x)return a.x<b.x;
 39     return a.y<b.y;
 40 }
 41 bool cmp2(Circle a,Circle b)
 42 {
 43     if((a.x+a.r)!=(b.x+b.r))return (a.x+a.r)<(b.x+b.r);
 44     return a.r>b.r;
 45 }
 46 inline int dis(Point a,Circle b)
 47 {
 48     return sqr(a.x-b.x)+sqr(a.y-b.y);
 49 }
 50 int main()
 51 {
 52     #ifndef ONLINE_JUDGE
 53     freopen("1.txt","r",stdin);
 54 //  freopen("2.txt","w",stdout);
 55     #endif
 56     int i,j,k;
 57     int x,y,z;
 58 //  for(scanf("%d",&cass);cass;cass--)
 59 //  for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
 60 //  while(~scanf("%s",s))
 61     while(~scanf("%d",&n))
 62     {
 63         ans=n;
 64         for(i=1;i<=n;i++)
 65             scanf("%d%d",&p[i].x,&p[i].y);
 66         sort(p+1,p+1+n,cmp1);
 67         scanf("%d",&m);
 68         for(i=1;i<=m;i++)
 69             scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].r);
 70         sort(c+1,c+1+m,cmp2);
 71         int last=1;
 72         for(i=1;i<=n;i++)
 73         {
 74             int l,r,mid;
 75             l=last;r=m;
 76             while(l<r)
 77             {
 78                 mid=(l+r)/2;
 79                 if(c[mid].x+c[mid].r>=p[i].x)r=mid;
 80                 else l=mid+1;
 81             }
 82             last=l;
 83             for(j=mid;j<=m;j++)
 84             {
 85                 if(dis(p[i],c[j])<=sqr(c[j].r))
 86                 {
 87                     ans--;
 88                     break;
 89                 }
 90                 if(c[j].x-c[j].r>p[i].x)break;
 91             }
 92         }
 93         printf("%d
",ans);
 94     }
 95     return 0;
 96 }
 97 /*
 98 //
 99  
100 //
101 */
View Code
原文地址:https://www.cnblogs.com/Coolxxx/p/6753532.html