HDU 1392 Surround the Trees【凸包周长】
来源:互联网 发布:淘宝店铺装修风格大全 编辑:程序博客网 时间:2024/06/05 07:52
转载请注明出处:http://blog.csdn.net/a1dark
分析:赤裸裸的凸包模板、我喜欢
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;struct node{int x,y;};node vex[1000];bool cmp1(node a,node b){if(a.y==b.y)return a.x<b.x;elsereturn a.y<b.y;}int cross(node,node,node);double dis(node,node);bool cmp(node a,node b){ int m=cross(vex[0],a,b); if(m==0) return dis(vex[0],a)-dis(vex[0],b)<=0?true:false; else return m>0?true:false;}node stackk[1000];int cross(node a,node b,node c){return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}double dis(node a,node b){return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y));}int main(){int t;while(scanf("%d",&t),t!=0){int i;for(i=0;i<t;i++){scanf("%d%d",&vex[i].x,&vex[i].y);}if(t==1)printf("%.2f\n",0.00);else if(t==2)printf("%.2f\n",dis(vex[0],vex[1]));else{ sort(vex,vex+t,cmp1); sort(vex+1,vex+t,cmp); memset(stackk,0,sizeof(stackk)); stackk[0]=vex[0]; stackk[1]=vex[1]; int top=1; for(i=2;i<t;i++){ while(i>=1&&cross(stackk[top-1],stackk[top],vex[i])<0)//对使用极角排序的i>=1有时可以不用,但加上总是好的 top--; //若使用黑书中第二种排序方法cmp1则必须加上, stackk[++top]=vex[i]; //控制<0或<=0可以控制重点,共线的,具体视题目而定。 } double s=0; for(i=1;i<=top;i++) s+=dis(stackk[i-1],stackk[i]); s+=dis(stackk[top],vex[0]); printf("%.2f\n",s);}}}
- HDU 1392 Surround the Trees【凸包周长】
- HDU 1392 Surround the Trees 凸包的周长
- HDU 1392 Surround the Trees(凸包周长)
- hdu 1392 Surround the Trees 凸包周长
- HDOJ 1392 Surround the Trees【凸包周长 Graham扫描】
- 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【凸包(求凸包周长)】【5月10】
- ZOJ 1453 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(凸包)
- C#实现测量程序运行时间及cpu使用时间
- CSS学习小结
- sharepreference的位置
- 修改表的列
- bat批处理小记
- HDU 1392 Surround the Trees【凸包周长】
- linux RAC asm_diskgroup未设置引起数据库实例无法打开
- 黑客是如何成长的
- iPhone开发笔记 scrollView和pageControl的搭配使用
- applicationcontext数据源配置本地路径
- HDFS架构
- 最簡單的東西總是最容易被忽視——談看不見的設計
- mysql general log
- 在 Ubuntu 上搭建 VPN 服务器