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;
} 

原文地址:https://www.cnblogs.com/isakovsky/p/11441000.html

时间: 2024-08-30 00:36:59

Codeforces gym102222 B.Rolling The Polygon 凸包/余弦定理的相关文章

Codeforces 437E The Child and Polygon(区间DP)

题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种分割方法,将多边形分割为多个三角形. 解题思路:首先要理解向量叉积的性质,一开始将给出的点转换成顺时针,然后用区间dp计算.dp[i][j]表示从点i到点j可以有dp[i][j]种切割方法.然后点i和点j是否可以做为切割线,要经过判断,即在i和j中选择的话点k的话,点k要在i,j的逆时针方. #include <cstdio> #include <cstring&g

HDU4033:Regular Polygon(二分+余弦定理)

Problem Description In a 2_D plane, there is a point strictly in a regular polygon with N sides. If you are given the distances between it and N vertexes of the regular polygon, can you calculate the length of reguler polygon's side? The distance is

POJ 2007 Scrambled Polygon(凸包)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7568   Accepted: 3604 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the

hdu 4033Regular Polygon(二分+余弦定理)

Regular Polygon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 3274    Accepted Submission(s): 996 Problem Description In a 2_D plane, there is a point strictly in a regular polygon with N side

Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包

原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. 然后我们建个凸包. 如果凸包上有大于2段颜色(就是至少四段),比如这样 那么必然无解. 否则就只有一段颜色或者两段颜色: 这里我们先不管这个,考虑一个三角形的构造. 考虑三角形三个顶点颜色不全相同的情况,例如: (两个白点的情况是等价的) 假如三角形区域内没有白点,那么直接全部连到其中一个黑点就好了

动态凸包 学习总结

动态凸包就是可以支持动态插入点,维护凸包信息的一类问题 又考到了,又被炸飞了(然而其实弱的连凸包性质都看不出来 注意只能支持动态插入点,而不支持动态删除和插入 不过删除的话如果不强制在线反过来就是插入啊OwO 不是很喜欢水平序的动态凸包,因为要维护上下两个凸壳好烦 所以就学了一发极角序 大概做法是以极角序为键值用平衡树维护凸包上的点 每次插入的时候找到插入点的前驱后继,用叉积判断是否在内部 如果不在就插入,插入之后不断的判断插入后前驱是否在凸包内和后继是否在凸包内 并且不断的删除直至不能删除为止

2019银川网络赛

??A. Maximum Element In A Stack ??B. Rolling The Polygon ??C. Caesar Cipher ??D. Take Your Seat E. 2-3-4 Tree ??F. Moving On G. Factories 树形DP + 背包 https://blog.csdn.net/dllpXFire/article/details/81085093 https://blog.csdn.net/starlet_kiss/article/de

Codeforces 50C Happy Farm 5 凸包

题目链接:点击打开链接 == 难得的y出了一道计算几何.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <iostream> using namespace std; #define INF 999999999.9 #define PI acos(-1.0) #define ll long long struct Poi

CodeForces - 38E Let&#39;s Go Rolling!

Description On a number axis directed from the left rightwards, n marbles with coordinates x1,?x2,?...,?xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material po