Codeforces gym102222 B.Rolling The Polygon 凸包/余弦定理
题意:
有一个不保证凸的多边形,让你滚一圈,计算某点滚出的轨迹多长。
题解:
求出凸包后,以每个点为转轴,转轴到定点的距离为半径,用余弦定理计算圆心角,计算弧长。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
int t,case1=;
cin>>t;
while(t--)
{
case1++;
int n;
cin>>n;
int x[],y[];//贮存坐标
for(int i=;i<=n;i++)
{
cin>>x[i]>>y[i];
}
int xx,yy;
cin>>xx>>yy;
double dis[];
for(int i=;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[];
for(int i=;i<=n;i++)
{
double t1,t2,t3;
if(xx==x[i]&&yy==y[i])
continue;
if(i==)
{
t1=sqrt((x[]-x[])*(x[]-x[])+(y[]-y[])*(y[]-y[]));
t2=sqrt((x[n]-x[])*(x[n]-x[])+(y[n]-y[])*(y[n]-y[]));
t3=sqrt((x[n]-x[])*(x[n]-x[])+(y[n]-y[])*(y[n]-y[]));
}
else if(i==n)
{
t1=sqrt((x[n]-x[])*(x[n]-x[])+(y[n]-y[])*(y[n]-y[]));
t2=sqrt((x[n]-x[n-])*(x[n]-x[n-])+(y[n]-y[n-])*(y[n]-y[n-]));
t3=sqrt((x[n-]-x[])*(x[n-]-x[])+(y[n-]-y[])*(y[n-]-y[]));
}
else
{
t1=sqrt((x[i+]-x[i])*(x[i+]-x[i])+(y[i+]-y[i])*(y[i+]-y[i]));
t2=sqrt((x[i]-x[i-])*(x[i]-x[i-])+(y[i]-y[i-])*(y[i]-y[i-]));
t3=sqrt((x[i-]-x[i+])*(x[i-]-x[i+])+(y[i-]-y[i+])*(y[i-]-y[i+]));
}
//cout<<t1<<" "<<t2<<" "<<t3<<" ";
ankle[i]=acos((t1*t1+t2*t2-t3*t3)/(*t1*t2));
//cout<<ankle[i]<<" ";
//cout<<endl;
} double l=;
for(int i=;i<=n;i++)
{
l+=sqrt(dis[i])*(acos(-1.0)-ankle[i]);
}
printf("Case #%d: %.3lf\n",case1,l);
}
return ;
}
Codeforces gym102222 B.Rolling The Polygon 凸包/余弦定理的更多相关文章
- Codeforces 437E The Child and Polygon(间隔DP)
题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一 ...
- hdu 4033Regular Polygon(二分+余弦定理)
Regular Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)T ...
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 437E The Child and Polygon
http://codeforces.com/problemset/problem/437/E 题意:求一个多边形划分成三角形的方案数 思路:区间dp,每次转移只从一个方向转移(L,R连线的某一侧),能 ...
- Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
题意:如题 用Graham,直接就能得到逆时针的凸包,找到原点输出就行了,赤果果的水题- 代码: /* * Author: illuz <iilluzen[at]gmail.com> * ...
- 计蒜客 The 2018 ACM-ICPC Chinese Collegiate Programming Contest Rolling The Polygon
include <iostream> #include <cstdio> #include <cstring> #include <string> #i ...
随机推荐
- Random Point in Triangle
题目链接 题意:多组输入三角形各个顶点坐标p1,p2,p3,在三角形中任取一点p,计算 期望E=max(S(p,p1,p2),max(S(p,p1,p3),S(p,p2,p3))); 思路:用随机数找 ...
- AcWing 243. 一个简单的整数问题2 (树状数组)打卡
题目:https://www.acwing.com/problem/content/244/ 题意:区间加,区间查询 思路:我们把原先那个差分数组分解一下 ∑i=1x∑j=1ib[j]=∑i=1x(x ...
- 分布式系统理论基础2 :CAP
本文转自:https://www.cnblogs.com/bangerlee/p/5328888.html 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到 ...
- python sum()函数的用法
sum() 方法对系列进行求和计算.针对元组,列表.对字符串会报错 >>>sum([0,1,2]) 3 >>> sum((2, 3, 4), 1) # 元组计算总和 ...
- 建站手册-浏览器信息:Netscape 浏览器
ylbtech-建站手册-浏览器信息:Netscape 浏览器 1.返回顶部 1. http://www.w3school.com.cn/browsers/browsers_netscape.asp ...
- 改进持续交付中的CI环节
改进持续交付中的CI环节 在当前 DevOps 的趋势下,持续集成(CI)和持续部署(CD)具有支柱性地位,那么能够成功搭建 CI/CD 流水线就至关重要了. 今天我就讲一讲如何做好CI部分,让我们的 ...
- redis 入门之string
set 用法 #set key value 设置value为字符串的键值对redis> SET key "value" #对不存在的key设置value OK redis& ...
- 写第一个 swift,iOS 8.0程序
class ViewController: UIViewController { @IBAction func btn_click(sender : AnyObject) { println(&quo ...
- Spring Boot实现通用的接口参数校验
Spring Boot实现通用的接口参数校验 Harries Blog™ 2018-05-10 2418 阅读 http ACE Spring App API https AOP apache IDE ...
- HashSet、LinkedHashSet、TreeSet的区别
HashSet:哈希表是通过使用称为散列法的机制来存储信息的,元素并没有以某种特定顺序来存放: LinkedHashSet:以元素插入的顺序来维护集合的链接表,允许以插入的顺序在集合中迭代: Tree ...