Wall(poj1113凸包+圆的弧长)
来源:互联网 发布:statistica软件 编辑:程序博客网 时间:2024/04/28 23:21
题意:给一些点,用一个多边形把这些点包起来,并且所有点到边的距离至少为L
思路:先求一个凸包然后再加上一个圆的弧长,为什么加圆的弧长呢?可以证明每个顶点到他距离为L的点组成了一个圆弧,过该点做两条垂线可以证明所有点的这些圆弧这些角度加起来正好360度是一个圆,所有就加上一个半径为L的圆
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespace std;struct Point{double x,y;Point(double x = 0,double y = 0) : x(x),y(y) {}};typedef Point Vector;Vector operator + (Vector a,Vector b) { return Vector(a.x+b.x,a.y+b.y) ;}Vector operator - (Vector a,Vector b) { return Vector(a.x-b.x,a.y-b.y) ;}Vector operator * (Vector a,double p) { return Vector(a.x*p,a.y*p) ;}Vector operator / (Vector a,double p) { return Vector(a.x/p,a.y/p) ;}const double eps = 1e-9;const double PI = acos(-1.0);double Dot(Vector a,Vector b) { return a.x*b.x + a.y*b.y ;}double Length(Vector a) { return sqrt(Dot(a,a)) ;}double Cross(Vector a,Vector b) { return a.x*b.y - a.y*b.x ;}int dcmp(double x){if(fabs(x) < eps) return 0;else return x < 0 ? -1 : 1;}bool operator < (Point a,Point b) { return a.x < b.x || (a.x == b.x && a.y < b.y) ;}bool operator == ( Point a, Point b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0 ;}double Angle(Vector a,Vector b) { return acos( Dot(a,b) / Length(a) / Length(b) ) ;}double Area(Point a,Point b,Point c) { return fabs(Cross(b-a,c-a))/2 ;}Vector Rotate(Vector a,double rad) { return Vector(a.x*cos(rad) - a.y*sin(rad),a.x*sin(rad) + a.y*cos(rad) );}Vector Normal(Vector a){double L = Length(a);return Vector(-a.y/L,a.x/L);}Point GetLineIntersection(Point p,Vector v,Point q,Vector w){Vector u = p - q;double t = Cross(w,u) / Cross(v,w);return p + v*t;}bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){double c1 = Cross(a2-a1,b1-a1) ,c2 = Cross(a2-a1,b2-a1),c3 = Cross(b2-b1,a1-b1),c4 = Cross(b2-b1,a2-b1);return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3) *dcmp(c3) < 0;}bool OnSengment(Point p,Point a,Point b){return dcmp(Cross(p-a,b-a)) == 0 && dcmp(Dot(a-p,b-p) < 0);}double PolyArea(Point *p,int n){double area = 0;int i;for(i = 0; i < n; i++){area += Cross(p[i]-p[0],p[i+1]-p[0]);}return area/2;}struct Line{Point s,e;};int ConvexHull(Point* p,int n,Point* ch){ sort(p,p+n); int m = 0; for(int i = 0; i < n; i++) { while( m > 1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--; ch[m++] = p[i]; } int k = m; for(int i = n-2 ; i >= 0; i--) { while(m > k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--; ch[m++] = p[i]; } if(n > 1) m--; return m;}Point p[1005];int main(){ int n,L; while(scanf("%d%d",&n,&L) != EOF) { for(int i = 0; i < n; i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } Point ch[1005]; int m = ConvexHull(p,n,ch); double ans = 0; for(int i = 0; i < m; i++) { ans += Length(ch[i]-ch[(i+1)%n]); } ans = ans + 2*PI * L; printf("%.0lf\n",ans); } return 0;}
- Wall(poj1113凸包+圆的弧长)
- POJ1113 Wall 凸包
- poj1113--Wall(凸包)
- poj1113 Wall 凸包
- poj1113 Wall --凸包
- poj1113 Wall【凸包】
- poj1113 Wall 凸包
- poj1113-Wall (国王的凸包)
- 【凸包_Graham】Wall POJ1113
- POJ1113 wall 简单凸包
- kyeremal-poj1113-Wall-凸包
- [POJ1113]Wall(凸包)
- POJ1113:Wall(凸包)
- POJ1113 Wall(凸包周长)
- POJ1113——Wall(凸包)
- poj1113——Wall(凸包)
- POJ1113——WALL 凸包
- POJ1113 Wall 凸包(Graham扫描法)
- session
- HDU 2993 MAX Average Problem(斜率优化)
- php文件上传
- C++中测试某算法耗时的方法
- NGUI研究院之开始学习制作第一个例子(一)
- Wall(poj1113凸包+圆的弧长)
- 解决STM32调试,无法进入main函数的问题
- 如何手动删除 Exchange 2010
- 利用 psyco 让 Python 程序执行更快
- thinkphp Model类方法一览
- JavaFX 3D部分介绍(2) Camera
- 如何开好迭代回顾会议(3)教练、不同的口味
- samba的一些基本命令
- datetime与smalldatetime之间的区别小结