hdu 1392(凸包)
来源:互联网 发布:mac连不上wifi 编辑:程序博客网 时间:2024/05/17 01:28
传送门
题意:几乎是模板题,求凸包的周长
用Graham扫描法解决(还有一个叫jarvis步行法,目测也差不多)。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;const int maxn=102;struct NODE { int x,y;}a[maxn],s[maxn];int top,n;inline int read() { int x=0;char c=getchar(); while (c<'0'||c>'9') c=getchar(); while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return x;}inline double dis(NODE a,NODE b) { return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}inline int cross(NODE a,NODE b,NODE c) { return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}inline int cmp1(NODE a,NODE b) { return a.y<b.y||(a.y==b.y&&a.x<b.x);}inline int cmp2(NODE c,NODE d) { int temp=cross(a[0],c,d); if (temp==0) return dis(a[0],c)<dis(a[0],d);//three points collinear return temp>0;}int main() {// freopen("hdu 1392.in","r",stdin); while (n=read()) { for (int i=0;i<n;++i) a[i].x=read(),a[i].y=read(); if (n==1||n==2) {printf("%.2lf\n",n^1?dis(a[0],a[1]):0.0);continue;}//special judge sort(a,a+n,cmp1),sort(a+1,a+n,cmp2), top=-1, s[++top]=a[0],s[++top]=a[1],s[++top]=a[2]; for (int i=3;i<n;++i) { while (top&&cross(s[top-1],s[top],a[i])<=0) --top; //strictly '<=', if three points are collinear, choose the first ans the last s[++top]=a[i]; } double c=0.0; for (int i=1;i<=top;++i) c+=dis(s[i-1],s[i]); c+=dis(s[top],s[0]); printf("%.2lf\n",c); } return 0;}
阅读全文
0 0
- hdu 1392(凸包)
- hdu-1392(二维凸包模板)
- hdu 1392(凸包周长)
- HDU 1392 HDU 1348 凸包
- hdu 1392 模板凸包
- hdu 1392 凸包问题
- hdu 1392凸包周长
- hdu 1392 凸包问题
- HDU Wall(凸包)
- hdu 4667(凸包)
- 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,POJ-3348(凸包周长,面积)
- HDU 1392 Surround the Trees(凸包)
- HDU 1392 Surround the Trees(凸包)
- vue2.0实现一个简单的轮播图
- java中打开文件的方法以及文件路径的写法
- viewpager设置子item宽度
- openwrt编写hello_world ipk
- MVC模式 探索
- hdu 1392(凸包)
- top n with ties
- 【模板】【图论】最近公共祖先(LCA)
- 8.15 N
- 文章标题 【Java源码浅析】关于HashMap和HashSet的异同和源码分析
- C Primer Plus 第二章
- Spring Bean的自动装配,注入及后处理器
- A
- memcached安装