poj 1113 Wall凸包
2017-07-29 10:35
381 查看
凸包入门。点这里
画图就能看出来周长就是一个圆+凸包周长
大佬的模板
一次循环求上部
一次循环求下部
画图就能看出来周长就是一个圆+凸包周长
大佬的模板
一次循环求上部
一次循环求下部
#include<iostream> #include<stdio.h> #include<math.h> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; struct node { double x;double y; }p[400005],s[400005]; int n,m; int sq(int x) { return x*x; } double chaji(node a,node b) { return a.x*b.y-a.y*b.x; } double dist(node a,node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } node xl(node a,node b) { node c; c.x=a.x-b.x; c.y=a.y-b.y; return c; } bool cmp(node a,node b) { if(a.x==b.x) return a.y<b.y; else return a.x>b.x; } int main() { int n,l; while(scanf("%d %d",&n,&l)!=EOF) { memset(s,0,sizeof(s)); for (int i=0;i<n;i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } sort(p,p+n,cmp); int tot=0; for (int i=0;i<n;i++) { while(tot>1 && chaji(xl(s[tot-1],s[tot-2]),xl(p[i],s[tot-2]))<=0) tot--; s[tot++]=p[i]; } int k=tot; for (int i=n-2;i>=0;i--) { while(tot>k && chaji(xl(s[tot-1],s[tot-2]),xl(p[i],s[tot-2]))<=0) tot--; s[tot++]=p[i]; } if(n>1) tot--; double ans=0.0; for (int i=0;i<tot;i++) { ans+=dist(s[i],s[i+1]); } ans+=2*l*3.1415926; printf("%.0lf\n",ans); } return 0; }
相关文章推荐
- POJ 1113 Wall 凸包求周长
- POJ 1113(Wall)【凸包】
- POJ 1113 Wall(凸包周长)
- POJ 1113 WALL(凸包-计算几何)
- poj 1113 Wall 凸包
- POJ 1113 Wall (凸包)
- 【POJ】1113 Wall(凸包)
- POJ 1113 && HDU 1348 Wall (凸包周长 graham扫描法)
- POJ 1113 || HDU 1348: wall(凸包问题)
- POJ 1113 Wall 凸包求边长 Graham扫描法
- POJ 1113 wall 求凸包
- POJ 1113 Wall (凸包)
- Wall - POJ 1113(求凸包)
- POJ 1113 Wall(凸包)
- poj 1113 Wall 凸包
- POJ 1113 WALL (凸包问题)
- poj 1113 Wall 凸包的应用
- POJ 1113 Wall (凸包)
- 【计算几何】【求凸包】【POJ 1113】wall
- POJ 1113 Wall【凸包周长】