YbtOJ 824「计算几何初探」圆与连线

题目链接:YbtOJ #824

小 A 有一个平面直角坐标系,其中有一个圆心在原点的半径为 $r$ 的圆(即它的方程为 $x^2+y^2=r^2$)和 $n$ 个特殊点 $(x_i,y_i)$。

小 A 想知道最多能够留下多少个特殊点,满足任意两点连线不与圆相交。

$1\le n\le 2\times10^3$,$r,x_i,y_i\le5\times10^3$。

Tutorial

求出每个点与圆的两条切线,那么在这两条切线之间的其他点与该点的连线都会与圆相交,而切线外的点则不会。

实际上,我们把每个点与圆的两个切点看成一个区间(具体实现中,方便起见我们我们用 角度 来表示这个区间),那么点 $A$ 与其两条切线间的点 $B$,对应的区间必然包含(两点在圆的同侧)或是相离(两点在圆的异侧),也就是说两点连线无交当且仅当它们的区间是非包含关系的相交。

求角度的区间还是比较简单的,首先我们求出当前点的角度 $g$,然后求出当前点与圆心的连线和圆心向切线的垂线的夹角 $d$($\cos d=\frac{\sqrt{x^2+y^2}}{R}$),则 $[g-d,g+d]$ 就是对应的区间。(具体实现中最好把左右端点表示到 $[-\pi,\pi]$ 中,注意这里的区间包含或是相离是一样的,因此即使交换左右端点也没有关系。)

然后题意就被转化为在一个序列上选出若干个区间满足两两相交。

我们先将所有区间按左端点排序,不妨枚举最左边的区间,然后对之后所有满足与该区间相交的区间,按照右端点求一遍最长上升子序列,即可求出答案。

Solution

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
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define W while
#define I inline
#define RI register int
#define LL long long
#define Cn const
#define CI Cn int&
#define gc getchar
#define D isdigit(c=gc())
#define pc(c) putchar((c))
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
using namespace std;
namespace Debug{
Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;}
Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;}
#define gdb(...) _debug(#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
namespace FastIO{
Tp I void read(Ty& x){char c;int f=1;x=0;W(!D) f=c^'-'?1:-1;W(x=(x<<3)+(x<<1)+(c&15),D);x*=f;}
Ts I void read(Ty& x,Ar&... y){read(x),read(y...);}
Tp I void write(Ty x){x<0&&(pc('-'),x=-x,0),x<10?(pc(x+'0'),0):(write(x/10),pc(x%10+'0'),0);}
Tp I void writeln(Cn Ty& x){write(x),pc('\n');}
}using namespace FastIO;
Cn int N=2e3+10;Cn double pi=acos(-1);
int n,r,Ans;
#define PA pair<double,double>
#define MP make_pair
#define fi first
#define se second
PA a[N];double f[N];
int main(){
freopen("circle.in","r",stdin),freopen("circle.out","w",stdout);
RI i,j,x,y,top;double ang,cir;for(read(n,r),i=1;i<=n;i++) read(x,y),ang=atan2(y,x),cir=acos(1.0*r/sqrt(x*x+y*y)),(a[i].fi=ang-cir)<-pi&&(a[i].fi+=2*pi),(a[i].se=ang+cir)>pi&&(a[i].se-=2*pi),a[i].fi>a[i].se&&(swap(a[i].fi,a[i].se),0);
for(sort(a+1,a+n+1),i=1;i<=n;i++){
f[top=0]=a[i].se;for(j=i+1;j<=n;j++) if(a[j].fi>a[i].se) break ;else if(a[j].se>a[i].se) f[top]<=a[j].se?f[++top]=a[j].se:*lower_bound(f+1,f+top+1,a[j].se)=a[j].se;Ans=max(Ans,top+1);
}return writeln(Ans),0;
}