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 ...
随机推荐
- IEEE 754标准
IEEE 754-1985 was an industry standard for representing floating-point numbers in computers, officia ...
- 手机浏览器下IScroll中click事件
产品的h5页面几乎都使用了iscroll插件,如果a标签在iscroll里,在部分手机浏览器中会出现无法点击的情况,不管是绑定click事件还是使用a标签的href属性.href属性偶尔还会能点击,c ...
- C#通过WebBrowser快速扒站思路积累大量着陆页列表
现在工作方向已经越来越倾向于项目产品运营相关的东西.对线上运营也有了一定程度的了解. 配合一些技术性的操作,能极大的便利工作中的各种高难度任务,快速提升自我,积累丰富的经验和资源. 以近期制作LP为例 ...
- .net 基础错误-string.replace 方法
1.string string.Replace(string oldValue,string newValue) 返回一个新的字符串,其中当前示例中出现的所有指定字符串都替换另一个指定字符串 错误:总 ...
- Python之登陆接口设计
刚刚开始学习Python,第一个编写的程序. import os user_file = open('use_file.txt', 'r') user_list = user_file.readlin ...
- yoeman构建Asp.net core项目并且实现分层
在Mac上开发使用yoeman构建Asp.net core项目并且实现分层引用 1.Yoeman? yoeman是一个自动化脚手架工具.它提供很多generator,generator相当于Visua ...
- HighCharts学习
http://www.stepday.com/topic/?369 http://www.helloweba.com/view-blog-156.html
- LED板上芯片(COB)封装流程
LED 板上芯片(Chip On Board,COB)封装流程是,首先在基底表面用导热环氧树脂(一般用掺银颗粒的环氧树脂)覆盖硅片安放点, 然后将硅片 间接安放正在基底表面,热处理至硅片牢固地固定正在 ...
- JetBrains IntelliJ IDEA for Mac 15.0 破解版 – Mac 上强大的 Java 集成开发工具
应网友要求更新. IntelliJ IDEA 是最强大的 Java IDE 之一,由知名的Jetbrainsg公司出品,最新版本增加了大量强大易用的特性,比如 Java 8 的Lambda 表达式调试 ...
- 一个异或加密方案--C语言实现
核心代码: char encrypt( char f , char c) { return f^c; } int OutEncrypt( char *FilePath, char *SecretWor ...