Codeforces gym102222 B.Rolling The Polygon 凸包/余弦定理

Posted isakovsky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces gym102222 B.Rolling The Polygon 凸包/余弦定理相关的知识,希望对你有一定的参考价值。

题意:

有一个不保证凸的多边形,让你滚一圈,计算某点滚出的轨迹多长。

题解:

求出凸包后,以每个点为转轴,转轴到定点的距离为半径,用余弦定理计算圆心角,计算弧长。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()

    int t,case1=0;
    cin>>t;
    while(t--)
    
        case1++;
        int n;
        cin>>n;
        int x[55],y[55];//贮存坐标
        for(int i=1;i<=n;i++)
        
            cin>>x[i]>>y[i];
        
        int xx,yy;
        cin>>xx>>yy;
        double dis[55];
        for(int i=1;i<=n;i++)
        
            dis[i]=(x[i]-xx)*(x[i]-xx)+(y[i]-yy)*(y[i]-yy);
            //cout<<dis[i]<<endl;
        
        //cout<<endl;
        double ankle[55];
        for(int i=1;i<=n;i++)
        
            double t1,t2,t3;
            if(xx==x[i]&&yy==y[i])
            continue;
            if(i==1)
            
                t1=sqrt((x[2]-x[1])*(x[2]-x[1])+(y[2]-y[1])*(y[2]-y[1]));
                t2=sqrt((x[n]-x[1])*(x[n]-x[1])+(y[n]-y[1])*(y[n]-y[1]));
                t3=sqrt((x[n]-x[2])*(x[n]-x[2])+(y[n]-y[2])*(y[n]-y[2]));
            
            else if(i==n)
            
                t1=sqrt((x[n]-x[1])*(x[n]-x[1])+(y[n]-y[1])*(y[n]-y[1]));
                t2=sqrt((x[n]-x[n-1])*(x[n]-x[n-1])+(y[n]-y[n-1])*(y[n]-y[n-1]));
                t3=sqrt((x[n-1]-x[1])*(x[n-1]-x[1])+(y[n-1]-y[1])*(y[n-1]-y[1]));
            
            else
            
                t1=sqrt((x[i+1]-x[i])*(x[i+1]-x[i])+(y[i+1]-y[i])*(y[i+1]-y[i]));
                t2=sqrt((x[i]-x[i-1])*(x[i]-x[i-1])+(y[i]-y[i-1])*(y[i]-y[i-1]));
                t3=sqrt((x[i-1]-x[i+1])*(x[i-1]-x[i+1])+(y[i-1]-y[i+1])*(y[i-1]-y[i+1]));
            
            //cout<<t1<<" "<<t2<<" "<<t3<<" ";
            ankle[i]=acos((t1*t1+t2*t2-t3*t3)/(2*t1*t2));
            //cout<<ankle[i]<<" ";
            //cout<<endl;
        

        double l=0;
        for(int i=1;i<=n;i++)
        
            l+=sqrt(dis[i])*(acos(-1.0)-ankle[i]);
        
        printf("Case #%d: %.3lf\n",case1,l);
     
    return 0;
 

 

以上是关于Codeforces gym102222 B.Rolling The Polygon 凸包/余弦定理的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces - 102222C - Caesar Cipher

Codeforces - 102222H - Fight Against Monsters - 贪心

Maximum Element In A Stack Gym - 102222A思维+栈

gym102222KVertex Covers(高维前缀和,meet in the middle)

E. 2-3-4 Tree

Codeforces Gym 100269 Dwarf Tower (最短路)