Surround the Trees(凸包求周长)
Surround the Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9102 Accepted Submission(s): 3481
are a lot of trees in an area. A peasant wants to buy a rope to
surround all these trees. So at first he must know the minimal required
length of the rope. However, he does not know how to calculate it. Can
you help him?
The diameter and length of the trees are omitted,
which means a tree can be seen as a point. The thickness of the rope is
also omitted which means a rope can be seen as a line.
There are no more than 100 trees.
input contains one or more data sets. At first line of each input data
set is number of trees in this data set, it is followed by series of
coordinates of the trees. Each coordinate is a positive integer pair,
and each integer is less than 32767. Each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
题解:
当n==2时竟然还要特判,不等于二倍。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
struct Node{
double x,y;
friend int operator <(Node a,Node b){
if(a.x<b.x||a.x==b.x&&a.y<b.y)return ;
else return ;
}
}a[],ans[];
double cj(Node a,Node b,Node c){
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
double getl(Node a,Node b){
double x=a.x-b.x,y=a.y-b.y;
return sqrt(1.0*x*x+1.0*y*y);
}
int main(){
int N;
while(~scanf("%d",&N),N){
for(int i=;i<N;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
int k=;
if(N==){
puts("0.00");continue;
}
if(N==){
printf("%.2lf\n",getl(a[],a[]));continue;//手一滑写成a[2]了,坑了10分钟
}
sort(a,a+N);
for(int i=;i<N;i++){//下凸包;
while(k>&&cj(ans[k-],ans[k-],a[i])<=)k--;
ans[k++]=a[i];
}
int t=k;
for(int i=N-;i>=;i--){
while(k>t&&cj(ans[k-],ans[k-],a[i])<=)k--;
ans[k++]=a[i];
}
double length=; for(int i=;i+<k;i++){
length+=getl(ans[i],ans[i+]);
}
printf("%.2lf\n",length);
}
return ;
}
Surround the Trees(凸包求周长)的更多相关文章
- TZOJ 2569 Wooden Fence(凸包求周长)
描述 Did you ever wonder what happens to your money when you deposit them to a bank account? All banks ...
- zoj 1453 Surround the Trees(凸包求周长)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds Memory ...
- 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 (凸包)
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 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...
- hdu 1348 (凸包求周长)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) Mem ...
- hdu 1392 Surround the Trees 凸包裸题
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDUJ 1392 Surround the Trees 凸包
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 一些ASP.NET的小知识点
DataFormatString="{0:格式字符串}" 我们知道在DataFormatString 中的 {0}表示数据本身,而在冒号后面的格式字符串代表所们希望数据显示的格式; ...
- mysql 数据备份
一.备份数据库并下载到本地[db_backup.php] php代码: <?php // 数据库参数(此处测试,直接给定,项目中使用配置文件) $cfg_dbname = 'blog'; $cf ...
- Objective-C继承
继承只是想谈谈在OC中继承的理解:面向对象语言中一个主要的功能就是继承.继承可以使用现在类的所用功能,是对功能的扩展,通过继承创建的新类称为“子类”或“派生类”,被继承的称为“基类”或者“父类”.继承 ...
- UIImage缩放
+(UIImage *)scaleImage: (UIImage *)image scaleFactor:(float)scaleFloat { CGSize size = CGSizeMake(im ...
- 跳出for循环
如下面,有两个循环,break只能退出一个for循环,不能直接跳过第二个for循环 for (Type type : types) { for (Type t : types2) { if (some ...
- [Jobdu] 题目1367:二叉搜索树的后序遍历序列
题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 输入: 每个测试案例包括2行: 第一行为1个整数 ...
- (转)CreateThread与_beginthreadex本质区别
本文将带领你与多线程作第一次亲密接触,并深入分析CreateThread与_beginthreadex的本质区别,相信阅读本文后你能轻松的使用多线程并能流畅准确的回答CreateThread与_beg ...
- CV_EXPORTS定义及作用
CV_EXPORTS 常用如下: class CV_EXPORTS MatExpr; template<typename _Tp> class CV_EXPORTS Size_; CV_E ...
- 我用过的linux命令--安装Hadoop
1. hadoop软件传送给虚拟机 还是利用WinSCP把hadoop软件安装包,放到linux的Downloads文件夹中. 2. 选择安装目录 把hadoop安装包copy到这个安装目录中,这里我 ...
- 简单十步让你全面理解SQL
很多程序员认为SQL是一头难以驯服的野兽.它是为数不多的声明性语言之一,也因为这样,其展示了完全不同于其他的表现形式.命令式语言. 面向对象语言甚至函数式编程语言(虽然有些人觉得SQL 还是有些类似功 ...