题目的意思是一个多边形绕着多边形外一点旋转,扫过的面积是多少,
设距离旋转点最远的点的距离是r1(一定在多边形顶点),最近的点(可能在多边形边上)。
最远的点很好写吗,最近的点需要讨论一下来写,不过也不难写,题目精度的话,都用double就可以过了。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
double x[100100],y[100100],px,py;
double sqr(double x) {return x*x;}
double cj(double x1,double y1,double x2,double y2)
{
return (x1-px)*(y2-py)-(x2-px)*(y1-py);
}
int main()
{
double maxf=0;
double minf=1000000000000;
scanf("%d%lf%lf",&n,&px,&py);
for (int i=1;i<=n+1;i++)
{
if (i<=n)
{
scanf("%lf%lf",&x[i],&y[i]);
maxf=max(maxf,sqr(x[i]-px)+sqr(y[i]-py));
minf=min(minf,sqr(x[i]-px)+sqr(y[i]-py));
}
else
{
x[i]=x[n];
y[i]=y[n];
}
int tmp;
if (i==1) continue;
if (i>1&&i<=n) tmp=i-1;
else tmp=1;
if (fabs(x[i]-x[tmp])<1e-6)
{
if (((py>y[i]&&py<y[tmp])||(py>y[tmp]&&py<y[i]))&&minf>sqr(x[i]-px))
minf=sqr(x[i]-px);
}
else if (fabs(y[i]-y[tmp])<1e-6)
{
if (((px>x[i]&&px<x[tmp])||(px>x[tmp]&&px<x[i]))&&minf>sqr(y[i]-py))
minf=sqr(y[i]-py);
}
else
{
double k=-(x[tmp]-x[i])/(y[tmp]-y[i]);
double tmpx=px+1;
double tmpy=py+k;
if (cj(tmpx,tmpy,x[i],y[i])*cj(tmpx,tmpy,x[tmp],y[tmp])<0)
minf=min(minf,sqr(fabs(cj(x[i],y[i],x[tmp],y[tmp])))/(sqr(x[tmp]-x[i])+sqr(y[tmp]-y[i])));
}
}
printf("%.18f",(maxf-minf)*3.14159265358979323846264338);
return 0;
}