Ural 1332 把圆细分+圆内切,内含关系判定
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1332
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<queue> using namespace std; const double eps = 1e-8; const double PI = acos(-1.0); const double INF = 1000000000000000.000; struct Point{ double x,y; Point(double x=0, double y=0) : x(x),y(y){ } //构造函数 }; typedef Point Vector; struct Circle{ Point C; double r; Circle(Point C=Point(0,0),double r=0.0): C(C),r(r) {} Point getpoint(double ang){ //可以用来求圆上与x正半轴成ang度的点的坐标。 return Point(C.x +cos(ang)*r,C.y + sin(ang)*r); } }; Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);} Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);} Vector operator * (double p,Vector A){return Vector(A.x*p,A.y*p);} Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);} bool operator < (const Point& a,const Point& b){ return a.x < b.x ||( a.x == b.x && a.y < b.y); } int dcmp(double x){ if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } bool operator == (const Point& a, const Point& b){ return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } ///向量(x,y)的极角用atan2(y,x); inline double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; } inline double Length(Vector A) { return sqrt(Dot(A,A)); } inline double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; } Vector vecunit(Vector v){ return v / Length(v);} //单位向量 /*************************************分 割 线*****************************************/ const int maxn = 105; Circle cir[maxn]; int N; double R,r; int main() { //freopen("E:\\acm\\input.txt","r",stdin); cin>>N; for(int i=1;i<=N;i++){ scanf("%lf %lf",&cir[i].C.x,&cir[i].C.y); } scanf("%lf %lf",&R,&r); if(dcmp(R-r) < 0){ printf("0\n"); return 0; } Circle NewC; NewC.r = R; for(int i=1;i<=N;i++){ cir[i].r = r; } double ave = 2*PI / 3000; int ans = 0; for(int i=1;i<=N;i++){ for(double ang=0;ang<=2*PI;ang+=ave){ int temp = 1; Point P = cir[i].getpoint(ang); //在圆上取点。 NewC.C = P + R * (cir[i].C-P)/Length(cir[i].C-P); for(int j=1;j<=N;j++){ if(i == j) continue; if(dcmp(fabs(NewC.r-cir[j].r) - Length(NewC.C - cir[j].C)) >= 0) { temp++; } } ans = max(ans,temp); } } printf("%d\n",ans); }