题目地址:pdf版本
和上一个题目几乎是一模一样的,就不说思路了。
但是呢,这次是用for 50次写的二分,然后,容易wa的一点是,要把p[n] 也进行平移,漏掉了就wa了啊
代码:
#include
#include
#include
#include
#include
const long double eps=1e-10;
const long double PI=acos(-1.0);
using namespace std;
struct Point{
long double x;
long double y;
Point(long double x=0,long double y=0):x(x),y(y){}
void operator<<(Point &A) {cout<eps)-(x<-eps); }
int sgn(long double x) {return (x>eps)-(x<-eps); }
typedef Point Vector;
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 *(Vector A,long double p) { return Vector(A.x*p,A.y*p); }
Vector operator /(Vector A,long double p) {return Vector(A.x/p,A.y/p);}
ostream &operator<<(ostream & out,Point & P) { out<0) return Length(v3);
else return DistanceToLine(P, A, B);
}
Point GetLineProjection(Point P,Point A,Point B)
{
Vector v=B-A;
Vector v1=P-A;
long double t=Dot(v,v1)/Dot(v,v);
return A+v*t;
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
long double c1=Cross(b1-a1, a2-a1);
long double c2=Cross(b2-a1, a2-a1);
long double c3=Cross(a1-b1, b2-b1);
long double c4=Cross(a2-b1, b2-b1);
return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0 ;
}
bool OnSegment(Point P,Point A,Point B)
{
return dcmp(Cross(P-A, P-B))==0&&dcmp(Dot(P-A,P-B))<=0;
}
long double PolygonArea(Point *p,int n)
{
long double area=0;
for(int i=1;i &sol)
{
long double a=L.v.x;
long double b=L.p.x-C.c.x;
long double c=L.v.y;
long double d=L.p.y-C.c.y;
long double e=a*a+c*c;
long double f=2*(a*b+c*d);
long double g=b*b+d*d-C.r*C.r;
long double delta=f*f-4*e*g;
if(dcmp(delta)<0) return 0;
if(dcmp(delta)==0)
{
t1=t2=-f/(2*e);
sol.push_back(L.point(t1));
return 1;
}
else
{
t1=(-f-sqrt(delta))/(2*e);
t2=(-f+sqrt(delta))/(2*e);
sol.push_back(L.point(t1));
sol.push_back(L.point(t2));
return 2;
}
}
// 向量极角公式
long double angle(Vector v) {return atan2(v.y,v.x);}
int getCircleCircleIntersection(Circle C1,Circle C2,vector &sol)
{
long double d=Length(C1.c-C2.c);
if(dcmp(d)==0)
{
if(dcmp(C1.r-C2.r)==0) return -1; // 重合
else return 0; // 内含 0 个公共点
}
if(dcmp(C1.r+C2.r-d)<0) return 0; // 外离
if(dcmp(fabs(C1.r-C2.r)-d)>0) return 0; // 内含
long double a=angle(C2.c-C1.c);
long double da=acos((C1.r*C1.r+d*d-C2.r*C2.r)/(2*C1.r*d));
Point p1=C1.point(a-da);
Point p2=C1.point(a+da);
sol.push_back(p1);
if(p1==p2) return 1; // 相切
else
{
sol.push_back(p2);
return 2;
}
}
// 求点到圆的切线
int getTangents(Point p,Circle C,Vector *v)
{
Vector u=C.c-p;
long double dist=Length(u);
if(dcmp(dist-C.r)<0) return 0;
else if(dcmp(dist-C.r)==0)
{
v[0]=Rotate(u,PI/2);
return 1;
}
else
{
long double ang=asin(C.r/dist);
v[0]=Rotate(u,-ang);
v[1]=Rotate(u,+ang);
return 2;
}
}
// 求两圆公切线
int getTangents(Circle A,Circle B,Point *a,Point *b)
{
int cnt=0;
if(A.r0) // 外离 又有两条外公切线
{
long double ang_in=acos(rsum/d);
a[cnt]=A.point(base+ang_in);
b[cnt]=B.point(base+ang_in+PI);
cnt++;
a[cnt]=A.point(base-ang_in);
b[cnt]=B.point(base-ang_in+PI);
cnt++;
}
return cnt;
}
Point Zero=Point(0,0);
long double common_area(Circle C,Point A,Point B)
{
// if(A==B) return 0;
if(A==C.c||B==C.c) return 0;
long double OA=Length(A-C.c),OB=Length(B-C.c);
long double d=DistanceToLine(Zero, A, B);
int sg=sgn(Cross(A,B));
if(sg==0) return 0;
long double angle=Angle(A,B);
if(dcmp(OA-C.r)<=0&&dcmp(OB-C.r)<=0)
{
return Cross(A,B)/2;
}
else if(dcmp(OA-C.r)>=0&&dcmp(OB-C.r)>=0&&dcmp(d-C.r)>=0)
{
return sg*C.r*C.r*angle/2;
}
else if (dcmp(OA-C.r)>=0&&dcmp(OB-C.r)>=0&&dcmp(d-C.r)<0)
{
Point prj=GetLineProjection(Zero, A, B);
if(OnSegment(prj, A, B))
{
vector p;
Line L=Line(A,B-A);
long double t1,t2;
getLineCircleIntersection(L,C, t1, t2, p);
long double s1=0;
s1=C.r*C.r*angle/2;
long double s2=0;
s2=C.r*C.r*Angle(p[0],p[1])/2;
s2-=fabs(Cross(p[0],p[1])/2);
s1=s1-s2;
return sg*s1;
}
else
{
return sg*C.r*C.r*angle/2;
}
}
else
{
if(dcmp(OB-C.r)<0)
{
Point temp=A;
A=B;
B=temp;
}
Point inter_point;
long double t1,t2;
Line L=Line(A,B-A);
vector inter;
getLineCircleIntersection(L, C, t1, t2,inter);
if(OnSegment(inter[0], A, B))
inter_point=inter[0];
else
{
inter_point=inter[1];
}
// 两种方法求交点都可以
// Point prj=GetLineProjection(Zero, A, B);
//
// Vector v=B-A;
// v=v/Length(v);
// long long double mov=sqrt(C.r*C.r-d*d);
//
// if(OnSegment(prj+v*mov, A, B))
// {
// inter_point=prj+v*mov;
// }
// else
// {
// inter_point=prj+Vector(-v.x,-v.y)*mov;
// }
long double s=fabs(Cross(inter_point, A)/2);
s+=C.r*C.r*Angle(inter_point,B)/2;
return s*sg;
}
}
Point p[5500];
int main()
{
int n;
Circle C;
int index=0;
int T;
cin>>T;
long double P;
while(cin>>n)
{
for(int i=0;i>P;
for(int i=0;i<=n;i++) // wa!
p[i]=p[i]-C.c;
C.c=Zero;
long double l=0,r=1e4;
long double mid=l;
for(int tim=0;tim<50;tim++)
{
mid=l+(r-l)/2;
C.r=mid;
long double ans=0;
for(int i=0;i=area*P/100.0) r=mid;
else l=mid;
}
// if(mid-floor(mid)>0.5) mid+=1;
printf("Case %d: %.0Lf\n",++index,mid);
}
}