题目明明写的是线段和圆。。实际上是直线和圆,白白讨论了很多情况。。
这种转化老套路了
#include<bits/stdc++.h> using namespace std; typedef double db; const db eps=1e-8; const db pi=acos(-1); int sign(db k){ if (k>eps) return 1; else if (k<-eps) return -1; return 0; } int cmp(db k1,db k2){return sign(k1-k2);} int inmid(db k1,db k2,db k3){return sign(k1-k3)*sign(k2-k3)<=0;}// k3 在 [k1,k2] 内 struct point{ db x,y; point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};} point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};} point operator * (db k1) const{return (point){x*k1,y*k1};} point operator / (db k1) const{return (point){x/k1,y/k1};} int operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;} // 逆时针旋转 point turn(db k1){return (point){x*cos(k1)-y*sin(k1),x*sin(k1)+y*cos(k1)};} point turn90(){return (point){-y,x};} bool operator < (const point k1) const{ int a=cmp(x,k1.x); if (a==-1) return 1; else if (a==1) return 0; else return cmp(y,k1.y)==-1; } db abs(){return sqrt(x*x+y*y);} db abs2(){return x*x+y*y;} db dis(point k1){return ((*this)-k1).abs();} point unit(){db w=abs(); return (point){x/w,y/w};} }; int inmid(point k1,point k2,point k3){return inmid(k1.x,k2.x,k3.x)&&inmid(k1.y,k2.y,k3.y);} db cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;} db dot(point k1,point k2){return k1.x*k2.x+k1.y*k2.y;} db rad(point k1,point k2){return atan2(cross(k1,k2),dot(k1,k2));} struct circle{ point o; db r; int inside(point k){ if(sign(k.dis(o)-r)<=0)return 1; return 0; } }; point proj(point k1,point k2,point q){ // q 到直线 k1,k2 的投影 point k=k2-k1; return k1+k*(dot(q-k1,k)/k.abs2()); } vector<point> getCL(circle k1,point k2,point k3){ // 求直线和圆的交点,沿着 k2->k3 方向给出 , 相切给出两个 point k=proj(k2,k3,k1.o); db d=k1.r*k1.r-(k-k1.o).abs2(); if (sign(d)==-1) return {}; point del=(k3-k2).unit()*sqrt(max((db)0.0,d)); return {k-del,k+del}; } point A,B; circle c; int n; db R; vector<pair<point,int> >v; //离源点远的排在后面 bool cmp1(pair<point,int> a, pair<point,int> b){ if(a.first==b.first)return a.second>b.second; if(a.first.x==b.first.x)return a.first.y<b.first.y; return a.first.x<b.first.x; } int main(){ //freopen("01.in","r",stdin); cin>>n>>R>>B.x>>B.y; A.x=A.y=0;c.r=R; for(int i=1;i<=n;i++){ scanf("%lf%lf",&c.o.x,&c.o.y); vector<point> res=getCL(c,A,B); if(!res.size())continue; v.push_back(make_pair(res[0],1)); v.push_back(make_pair(res[1],-1)); } sort(v.begin(),v.end(),cmp1); int ans=0,now=0; for(int i=0;i<v.size();i++){ now+=v[i].second; ans=max(ans,now); } now=0; for(int i=v.size()-1;i>=0;i--){ now+=v[i].second; ans=max(ans,now); } cout<<ans<<' '; }