hdu Surround the Trees
题目链接:戳我
凸包模板
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MAXN 100010
using namespace std;
int n,top;
double ans;
struct Node{int x,y;}t[MAXN],s[MAXN];
inline bool cmp(struct Node a,struct Node b)
{
double A=atan2((a.y-t[1].y),(a.x-t[1].x));
double B=atan2((b.y-t[1].y),(b.x-t[1].x));
if(A!=B) return A<B;
else return a.x<b.x;
}
inline double cross(Node a,Node b,Node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}
inline void solve()
{
t[0]=(Node){0x3f3f3f3f,0x3f3f3f3f};
int k=0;
for(int i=1;i<=n;i++)
if(t[i].y<t[0].y||(t[i].y==t[0].y&&t[i].x<t[0].x))
t[0]=t[i],k=i;
swap(t[1],t[k]);
sort(&t[2],&t[1+n],cmp);
s[0]=t[1],s[1]=t[2];
top=1;
for(int i=3;i<=n;i++)
{
while(top&&cross(s[top-1],t[i],s[top])>=0.0) top--;
s[++top]=t[i];
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("ce.in","r",stdin);
#endif
for(;;)
{
ans=0.0;
scanf("%d",&n);
if(!n) break;
for(int i=1;i<=n;i++)
scanf("%d%d",&t[i].x,&t[i].y);
solve();
if(top==0)
ans=0;
else if(top==1)
ans=sqrt((s[0].x-s[1].x)*(s[0].x-s[1].x)+(s[0].y-s[1].y)*(s[0].y-s[1].y));
else
{
s[++top]=s[0];
for(int i=0;i<top;i++)
{
Node a=s[i],b=s[i+1];
ans+=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
}
printf("%.2lf\n",ans);
}
return 0;
}
hdu 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 凸包裸题
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 ...
- 【计算几何初步-凸包-Jarvis步进法。】【HDU1392】Surround the Trees
[科普]什么是BestCoder?如何参加? Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- Surround the Trees(凸包求周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Surround the Trees(凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 【315】Windows 之间代码自动传文件
对于 Windows 内部自动复制/移动文件可以通过 批处理 来完成,对于不同的电脑之间的实现也是相同的方法,但是需要将一台电脑的对应文件夹设置成 共享,只要在另一台电脑能够直接访问共享的文件夹,就可 ...
- javaScript字符串操作
JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...
- LeetCode之字符串处理题java
344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...
- Excel VBA入门(五)Excel对象操作
本章是本系列教程的重点.但我觉得应该不是难点.从第零章开始到学完本章,应该可以把VBA用于实战中了. Excel对象主要有4个: 工作薄 Workbook 工作表 Worksheet 单元格区域 Ra ...
- Kubuntu上连接PPTP
生活在天朝,如果没备几招FQ的本领,都不敢说自己还活着... 前两天从朋友那抢了个VPN帐号,使用的是PPTP的,在google上找了一会,发现网上大都是讲VPN服务搭建的,就算是介绍客户端的,也大都 ...
- MySQL5.6.35部署
1.下载软件 [root@localhost src]# wget -q http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glib ...
- 【转】JAVA 并发编程-多个线程之间共享数据
原文地址:http://blog.csdn.net/hejingyuan6/article/details/47053409# 多线程共享数据的方式: 1,如果每个线程执行的代码相同,可以使用同一个R ...
- jQuary总结4: jquery操作字符串
1 jquery操作DOM -1 创建元素 $('<span>这是一个span元素</span>'); //创建了一个jQuery包装的span,此时并没有添加到DOM树上 - ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- 编写高质量代码改善C#程序的157个建议——建议113:声明变量前考虑最大值
建议113:声明变量前考虑最大值 假设正在开发一个工资系统,其中一个模块负责处理加薪.代码如下: static void Main(string[] args) { ; salary = (); Co ...