HDU 1392 Surround the Trees(凸包)
来源:互联网 发布:男士 爽肤水 知乎 编辑:程序博客网 时间:2024/05/17 10:41
题面
懒得粘贴了。。。
大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长。
题解
直接求出凸包,统计一遍答案即可
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<queue>#include<algorithm>using namespace std;#define MAX 10000#define INF 1000000000int n,top;struct Node{ int x,y;}p[MAX],S[MAX];inline int read(){ int x=0,t=1;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-'){t=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} return x*t;}inline bool cmp(Node a,Node b){ double A=atan2((a.y-p[1].y),(a.x-p[1].x)); double B=atan2((b.y-p[1].y),(b.x-p[1].x)); if(A!=B)return A<B; else return a.x<b.x;}long long Cross(Node a,Node b,Node c){ return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(b.y-a.y)*(c.x-a.x);}void Get(){ p[0]=(Node){INF,INF};int k; for(int i=1;i<=n;++i) if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[i].x<p[0].x)) {p[0]=p[i];k=i;} swap(p[k],p[1]); sort(&p[2],&p[n+1],cmp); S[0]=p[1],S[1]=p[2];top=1; for(int i=3;i<=n;) { if(top&&Cross(S[top-1],p[i],S[top])>=0)top--; else S[++top]=p[i++]; }}inline double Dis(Node a,Node b){ return sqrt(1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y));}inline void GetAns(){ double Ans=0; if(top==0) Ans=0; else if(top==1) Ans=Dis(S[0],S[1]); else { S[++top]=S[0]; for(int i=0;i<top;++i) Ans+=Dis(S[i],S[i+1]); } printf("%.2f\n",Ans);}int main(){ while(233333) { n=read(); if(!n)break; for(int i=1;i<=n;++i) p[i]=(Node){read(),read()}; Get(); GetAns(); } return 0;}
阅读全文
1 0
- HDU 1392 Surround the Trees(凸包)
- hdu-1392 Surround the Trees(凸包)
- HDU 1392 Surround the Trees(凸包)
- hdu 1392 Surround the Trees 凸包
- hdu 1392 Surround the Trees【凸包】
- ZJU 1453(hdu 1392) Surround the Trees(凸包)
- hdu 1392 Surround the Trees(凸包)
- HDU-#1392 Surround the Trees(Graham & Andrew +凸包)
- hdu 1392 Surround the Trees( 凸包问题)
- HDU 1392 Surround the Trees(凸包模板)
- HDU 1392 Surround the Trees(凸包)
- HDU 1392 Surround the Trees(凸包)
- hdu 1392 Surround the Trees(凸包模板)
- hdu 1392 Surround the Trees(凸包模版)
- hdu 1392 Surround the Trees 基础 二维凸包 算法
- hdu 1392 Surround the Trees 凸包模板题
- HDU 1392 Surround the Trees 构造凸包
- HDU 1392 Surround the Trees【凸包周长】
- 数组翻转
- unreal engine 4学习笔记:蓝图脚本
- 浅谈HTTP中Get与Post的区别(转)
- Go语言学习笔记 --- 常量的定义详解
- Activity Hook
- HDU 1392 Surround the Trees(凸包)
- 数据结构 c语言 顺序查找算法(linux下实现)
- Redis的持久化之RDB方式
- java的4种权限修饰符
- QLineEdit 用法总结
- Java对数据库的调用一些常用方法总结
- hpuoj 【1042】假币问题【思维】&&【数学】
- 莫比乌斯反演
- 如何在spyder中查看python内置函数的源码