其他分享
首页 > 其他分享> > B. Rolling The Polygon(几何+余弦定理)

B. Rolling The Polygon(几何+余弦定理)

作者:互联网

B. Rolling The Polygon(几何+余弦定理)

题目链接:https://nanti.jisuanke.com/t/41286

题意:一个n边形内含有一点p,多边形从一条边开始沿其延长线旋转一周,问p的运动长度。

思路:容易推出, p点每一小段的弧长都是一本分圆周运动, 求出多边形每个角的大小和p点距离每个角的距离就能得出答案。

代码:

#include<bits/stdc++.h>

using namespace std;

int x[55];
int y[55];
int xx,yy;
int n,a;

int main()
{
    scanf("%d",&a);
    for(int p=1;p<=a;p++)
    {
        scanf("%d",&n);
        for ( int i=1; i<=n; i++ ) {
            scanf("%d %d",&x[i],&y[i]);
        }
        x[0] = x[n]; y[0] = y[n];
        x[n+1] = x[1]; y[n+1] = y[1];
        scanf("%d %d",&xx,&yy);
        double ans = 0;
        for ( int i=1; i<=n; i++ ) {
            double dis = sqrt( (x[i]-xx)*(x[i]-xx) + (y[i]-yy)*(y[i]-yy) );
            double cs = 1.0*((x[i-1]-x[i])*(x[i+1]-x[i])+(y[i-1]-y[i])*(y[i+1]-y[i]))/( sqrt((x[i-1]-x[i])*(x[i-1]-x[i])+ (y[i-1]-y[i])*(y[i-1]-y[i]) )*sqrt((x[i+1]-x[i])*(x[i+1]-x[i])+ (y[i+1]-y[i])*(y[i+1]-y[i]) )  );
            double o = acos(cs);
            ans +=  (acos(-1)-o)*dis;
        }
        printf("Case #%d: ",p);
        printf("%.3f\n",ans);
    }
    return 0;
}

 

标签:多边形,Polygon,int,55,余弦定理,Rolling
来源: https://blog.csdn.net/weixin_43828245/article/details/100176227