标签:多边形 out color case 弧长 一个 i++ 半径 nbsp
题意:
有一个不保证凸的多边形,让你滚一圈,计算某点滚出的轨迹多长。
题解:
求出凸包后,以每个点为转轴,转轴到定点的距离为半径,用余弦定理计算圆心角,计算弧长。
#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 凸包/余弦定理
标签:多边形 out color case 弧长 一个 i++ 半径 nbsp
原文地址:https://www.cnblogs.com/isakovsky/p/11441000.html