求凸包周长
来源:互联网 发布:百度seo排名点击软件 编辑:程序博客网 时间:2024/04/28 07:01
#include <map>#include <set>#include <vector>#include <math.h>#include <string>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>#include <algorithm>#include <functional>const double pi = acos(-1.0);using namespace std;const int MAXN=10005;const double eps=1e-2;int dcmp(double x){ if(fabs(x)<eps)return 0; if(x>0)return 1; return -1;} //弄精度struct Point { double x,y;}p[MAXN]; //搞点double dot(Point a,Point b,Point c){ double s1=b.x-a.x; double t1=b.y-a.y; double s2=c.x-a.x; double t2=c.y-a.y; return s1*s2+t1*t2;} //点积int n,res[MAXN],top;//全局变量,n是给出点的个数,top是凸包顶点的个数,res[]存排序后凸包上点的下标bool cmp(Point a,Point b){ if(a.y==b.y)return a.x<b.x; return a.y<b.y;}bool mult(Point sp,Point ep,Point op){ return (sp.x-op.x)*(ep.y-op.y)>=(ep.x-op.x)*(sp.y-op.y);}void Graham(){ int len; top=1; sort(p,p+n,cmp); if(n==0)return;res[0]=0; if(n==1)return;res[1]=1; if(n==2)return;res[2]=2; for(int i=2;i<n;i++){ while(top&&mult(p[i],p[res[top]],p[res[top-1]]))top--; res[++top]=i; } len=top; res[++top]=n-2; for(int i=n-3;i>=0;i--){ while(top!=len&&mult(p[i],p[res[top]],p[res[top-1]]))top--; res[++top]=i; }} //求凸包 double dist(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int main(){ int m,t,l; cin>>t; while(t--) { cin>>m>>l; n=m; for(int i=0;i<m;i++) scanf("%lf%lf",&p[i].x,&p[i].y); Graham(); double sum=0; for(int i=0;i<top;i++) sum+=dist(p[res[i]],p[res[i+1]]); sum+=2*pi*l; printf("%.0lf\n",sum); if(t!=0)printf("\n");} return 0;}
0 0
- 求凸包周长
- 2731: Greedyman 求凸包周长
- 分治求凸包周长
- hdu1348 Wall (求凸包周长)
- hdu 1392(求凸包周长)
- poj1348求凸包周长
- 【解题报告】 POJ 1113 Wall -- 求凸包周长
- 凸包算法,并求凸包的周长
- 求凸包的周长(计算几何模板)
- poj1113 求凸包+计算凸包周长
- poj1113Wall 求凸包周长 Graham扫描法
- HDU 4667 Building Fence(求凸包的周长)
- hdu1392 Surround the Trees (求凸包周长)
- hdoj 1392 Surround the Trees 【求凸包周长】
- POJ 1113 Wall(求凸包周长)
- HDU 4667 Building Fence(求凸包的周长)
- HDU 1392 Surround the Trees(求凸包周长)
- 二维凸包(模板) hdu 1348 求凸包的周长
- Mycat生产实践---性能调优
- 在原型设计上,UI和UX设计师有哪三个区别?
- 求凸包上最远两点距离的平方值
- 关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
- RecycleView加载不同条目
- 求凸包周长
- imx6 yocto编译备忘
- React-native学习过程 一 改变文字,添加图片
- RSS 教程
- 慎用百度!!!搜出来的资料坑死人!
- OOP/第三章 多态
- 155. Min Stack
- jvm堆外直接内存实现高性能接入层
- dp问题 插花