杭电 1392 Surround the Trees
来源:互联网 发布:软件自带音效 编辑:程序博客网 时间:2024/06/06 18:10
经典凸包问题!!!!
AC代码如下:
#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<cstdio>using namespace std;struct H{ double x,y;}trees[105];bool cmp(H a,H b){ return a.x<b.x||(a.x==b.x&&a.y<b.y);}int xj(double x1,double y1,double x2,double y2){ if(x1*y2-x2*y1<=0) return 1; else return 0;}int main(){ int n; int i,j,tt; double fx,fy,sx,sy,xx,yy; double a[105],b[105]; while(cin>>n,n) { tt=0; for(i=0;i<n;i++) cin>>trees[i].x>>trees[i].y; sort(trees,trees+n,cmp); for(i=0;i<n;i++) { while(tt>1&&xj(a[tt-1]-a[tt-2],b[tt-1]-b[tt-2],trees[i].x-a[tt-2],trees[i].y-b[tt-2])) tt--; a[tt]=trees[i].x;b[tt++]=trees[i].y; } int k=tt; for(i=n-2;i>=0;i--) { while(tt>k&&xj(a[tt-1]-a[tt-2],b[tt-1]-b[tt-2],trees[i].x-a[tt-2],trees[i].y-b[tt-2])) tt--; a[tt]=trees[i].x;b[tt++]=trees[i].y; } double sum=0; for(i=1;i<tt;i++) { sum+=sqrt((a[i]-a[i-1])*(a[i]-a[i-1])+(b[i]-b[i-1])*(b[i]-b[i-1])); } if(n==2) printf("%.2f\n",sum/2); else printf("%.2f\n",sum); } return 0;}
1 0
- 杭电1392-Surround the Trees
- 杭电 1392 Surround the Trees
- 1392 Surround the Trees
- 杭电OJ(HDOJ)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
- hdu 1392 Surround the Trees
- Surround the Trees(hdu 1392)
- hdu 1392 Surround the Trees
- HDU - 1392 Surround the Trees
- HDU 1392 Surround the Trees
- Java线程池的原理及几类线程池的介绍
- hadoop2.4.1在64位Deepin/Ubuntu系统中编译安装
- OpenStack云计算快速入门之二:OpenStack安装与配置
- Linux 文本 查找命令小结之grep
- 腾讯QQ企业邮箱POP3/SMTP设置
- 杭电 1392 Surround the Trees
- MFC六大核心机制之二:运行时类型识别(RTTI)
- POJ 3276(第二篇)开关问题
- cocos2dx 添加一个新建层的方法。
- Android单元测试
- 黑马程序员-java面试题-银行业务调度系统
- SCN号概述
- D:\VC98\CRT\SRC\DBGHEAP.C
- DSBase的最初的初衷