zoj 1453 Surround the Trees Andrew算法
来源:互联网 发布:mac桌面图标消失 编辑:程序博客网 时间:2024/06/05 09:54
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;struct Point{ int x,y;}p[1024],ch[1024];Point operator - (Point a,Point b){ Point c; c.x=a.x-b.x; c.y=a.y-b.y; return c;}int cross(Point a,Point b){ return a.x*b.y-b.x*a.y;}double dot(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}bool cmp(Point a,Point b){ if(a.x==b.x) return a.y<b.y; else return a.x<b.x;}int main(){ int i,n,m; double ans; while(~scanf("%d",&n)) { if(n==0) break; for(i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); if(n==1){printf("0.00\n");continue;} else if(n==2) {printf("%.2f\n",dot(p[0],p[1])*2);continue;} sort(p,p+n,cmp); m=0; for(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(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--; ans=0; for(i=0;i<m;i++) { ans+=dot(ch[i],ch[i+1]); } printf("%.2f\n",ans); } return 0;}
0 0
- zoj 1453 Surround the Trees Andrew算法
- zoj 1453 Surround the Trees
- zoj 1453 Surround the Trees
- zoj 1453 Surround the Trees (求凸包的周长)
- ZOJ 1453 Surround the Trees(凸包入门:求凸包周长)
- zoj 1453 Surround the Trees(求凸包周长)
- ZOJ 1453 Surround the Trees(求凸包周长 刘汝佳模板)
- HDU-#1392 Surround the Trees(Graham & Andrew +凸包)
- zoj 1453 Surround the Trees(我的第一个凸包,哇咔咔)
- ZOJ - 1453 —— Surround the Trees (求凸包的周长)
- ZJU 1453 Surround the Trees 凸包
- 1392 Surround the Trees
- Surround the Trees
- Surround the Trees
- Surround the Trees
- Surround the Trees
- hdu1392-Surround the Trees
- Surround the Trees
- iOS第三管理工具pods
- 社説 20150829 自民党総裁選 無投票再選も前向きな選択肢
- Android手游发行兵器谱
- 对面向过程,对象,接口,切面的理解
- Leetcode: Contains Duplicate II
- zoj 1453 Surround the Trees Andrew算法
- 前端的色彩选择
- DirectX3D游戏开发五 简单模型创建(索引缓存)
- 阿里校招内推总结
- iOS开发者,你不可错过的资源
- 机器学习算法与Python实践之(二)支持向量机(SVM)初级
- void * 指针介绍
- ACM学习-匈牙利匹配
- linux学习笔记----进程管理----杀死进程and 把进程放入后台