Rolling The Polygon
题意:
- 一个n边形中有一个随机的点x,然后将n边形绕n边形的一个顶点开始旋转,旋转角度为它对应的角的补角,最后输出n边形中的那个随机点x的路径长度。
思路:
- 每将n边形转一次,就是以随机点
到旋转点的距离为半径,以旋转角为圆心角的弧长。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1e5+10;
const double ESp=1e-7;
const double PI=acos(-1.0);
double r[60];
int n;
struct node
{
double x,y;
}p[60],now;
double ans;
double add(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double sum(int i)
{
int x,y;
x=i+1;
y=i-1;
if(x>n)
{
x=1;
}
if(y<=0)
{
y=n;
}
double b1=add(p[x],p[i]);
double b2=add(p[y],p[i]);
double b3=add(p[x],p[y]);
double du=acos((pow(b1,2.0)+pow(b2,2.0)-pow(b3,2.0))/(2.0*b1*b2));//(余弦定理)旋转点对应的n边形内角
return abs((PI-du)*r[i]);
}
int main( )
{
int t,k=0;
scanf("%d",&t);
while(t--)
{
k++;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
scanf("%lf%lf",&now.x,&now.y);
for(int i=1;i<=n;i++)
{
r[i]=add(now,p[i]);//每个点到随机点x的距离
}
ans=0;
for(int i=1;i<=n;i++)
{
ans+=sum(i);
}
cout<<"Case #"<<k<<": ";
printf("%.3lf\n",ans);
}
return 0;
}
网友评论