hdu 1392 Surround the Trees
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1392
题意:给出一些点的坐标,求最小的凸多边形把所有点包围时此多边形的周长。
解法:凸包ConvexHull 模板题
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<cstdlib>
- #include<algorithm>
- #define inf 0x7fffffff
- #define PI 3.141592654
- #define exp 1e-10
- using namespace std;
- struct Point
- {
- double x,y;
- Point (double x=,double y=):x(x),y(y){}
- friend bool operator < (Point A,Point B)
- {
- if (A.x != B.x) return A.x < B.x;
- return A.y<B.y;
- }
- }an[];
- typedef Point Vector;
- Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x , A.y+B.y); }
- Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x , A.y-B.y); }
- int dcmp(double x)
- {
- if (fabs(x)<exp) return ;
- else return x< ? - : ;
- }
- double cross(Vector A,Vector B)
- {
- return A.x*B.y-B.x*A.y;
- }
- int ConvexHull(Point *p,int n,Point *ch)
- {
- sort(p,p+n);
- int m=;
- for (int i= ;i<n ;i++)
- {
- while (m> && dcmp(cross(ch[m-]-ch[m-] , p[i]-ch[m-]))<=) m--;
- ch[m++]=p[i];
- }
- int k=m;
- for (int i=n- ;i>= ;i--)
- {
- while (m>k && dcmp(cross(ch[m-]-ch[m-] , p[i]-ch[m-]))<=) m--;
- ch[m++]=p[i];
- }
- ch[m++]=ch[];
- if (n>) m--;
- return m;
- }
- double dis(Point a,Point b)
- {
- return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
- }
- int main()
- {
- int n;
- while (cin>>n,n)
- {
- for (int i= ;i<n ;i++)
- scanf("%lf%lf",&an[i].x,&an[i].y);
- if (n==) {printf("0.00\n");continue;}
- else if (n==) {printf("%.2f\n",dis(an[],an[]));continue;}
- Point bn[];
- int m=ConvexHull(an,n,bn);
- double sum=;
- for (int i= ;i<m ;i++)
- {
- sum += dis(bn[i],bn[i+]);
- }
- printf("%.2f\n",sum);
- }
- return ;
- }
hdu 1392 Surround the Trees的更多相关文章
- HDU 1392 Surround the Trees(凸包入门)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- HDU 1392 Surround the Trees (凸包周长)
题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...
- hdu 1392 Surround the Trees 凸包裸题
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees (凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
- 计算几何(凸包模板):HDU 1392 Surround the Trees
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...
随机推荐
- RecyclerView中显示不同的item
测试代码: activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an ...
- 如何创建ajax对象?
1.IE低版本 2.非IE和高版本 <script> function createAjax(){ var request=false; //window对象中有XMLHttpReques ...
- 代码重启SQL命令
1.net stop mssqlserver --停止mssqlserver 2.net start mssqlserver --开始mssqlserver
- jquery.unobtrusive-ajax.js的扩展,做到片段式加载
//ajax支持库 /*! ** Unobtrusive Ajax support library for jQuery ** Copyright (C) Microsoft Corporation. ...
- salt-ssh安装及简单使用
需要 salt-master 0.17以上版本支持 1.安装 相关依赖包可查看requirements.txt Jinja2 M2Crypto msgpack-python pycrypto PyYA ...
- ListView用法及加载数据时的闪烁问题和加载数据过慢问题
ListView介绍及添加数据时的闪烁问题 1. ListView类 1.1 ListView常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示 ...
- ES6 入门系列 - let 和 const 命令
let命令 基本用法 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = ; ; } a // ReferenceEr ...
- zip解压缩
package com.green.project.compress; import java.io.File;import java.io.FileInputStream;import java.i ...
- Oracle 11g Windows 迁移至 Linux
OS: windows server 2008 R2 enterprise DB: 11.2.0.1.0 数据库配置: ORACLE_BASE=D:\app\Administrator ORACLE_ ...
- EXCEL处理数据小技巧
1.EXCEL 中如何获得4*8这个数字中,*号前面的数字 输入 =LEFT(AC2,FIND("*",AC2)-1) 获得*右边的数字 输入 =RIGHT(AC2,FIND(& ...