hdu 1392 Surround the Trees 凸包裸题
Surround the Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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.
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
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; const int MAXN = ;
struct Point
{
double x,y;
Point() {}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x= tx*cos(B) - ty*sin(B);
y= tx*sin(B) + ty*cos(B);
}
};
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
Point listt[MAXN];
int Stack[MAXN],top,n; //相对于listt[0]的极角排序
bool _cmp(Point p1,Point p2)
{
double tmp = (p1-listt[])^(p2-listt[]);
if(sgn(tmp) > )return true;
else if(sgn(tmp) == && sgn(dist(p1,listt[]) - dist(p2,listt[])) <= ) return true;
else return false;
}
void Graham(int n)
{
top=;
Point p0;
int k = ;
p0 = listt[]; //找最下边的一个点
for(int i = ; i < n; i++)
{
if( (p0.y > listt[i].y) || (p0.y == listt[i].y && p0.x > listt[i].x) )
{
p0 = listt[i];
k = i;
}
}
swap(listt[k],listt[]);
sort(listt+,listt+n,_cmp);
if(n == )
{
top = ;
Stack[] = ;
printf("0.00\n");
return;
}
if(n == )
{
top = ;
Stack[] = ;
Stack[] = ;
double dis=dist(listt[Stack[]],listt[Stack[]]);
printf("%.2f\n",dis);
return ;
}
Stack[] = ;
Stack[] = ;
top = ;
for(int i = ; i < n; i++)
{
while(top > && sgn((listt[Stack[top-]]-listt[Stack[top-]])^(listt[i]-listt[Stack[top-]])) <= )
top--;
Stack[top++] = i;
}
double ans=;
for(int i=; i<top; i++)
{
ans+=dist(listt[Stack[i]],listt[Stack[i-]]);
}
ans+=dist(listt[Stack[top-]],listt[Stack[]]);
printf("%.2f\n",ans);
}
int main ()
{
while(~scanf ( "%d", &n ) )
{
if(!n)break;
for(int i=; i<n; i++)
scanf ( "%lf%lf", &listt[i].x, &listt[i].y );
Graham(n);
}
return ;
}
hdu 1392 Surround the Trees 凸包裸题的更多相关文章
- 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: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(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
- 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 ...
- HDUJ 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
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...
随机推荐
- HDU 3172 Virtual Friends (map+并查集)
These days, you can do all sorts of things online. For example, you can use various websites to make ...
- pyqt5界面切换
#主要的思路就是创建两个frame(如果有两个以上同理)使用setVisible()函数显示或者隐藏frame 参数是bool值import sys from PyQt5.QtWidgets impo ...
- django field
name=models.CharField(max_length=30,unique=True,verbose_name='姓 名') birthday=models.DateField(bla ...
- Spring Boot(十七):使用Spring Boot上传文件
Spring Boot(十七):使用Spring Boot上传文件 环境:Spring Boot最新版本1.5.9.jdk使用1.8.tomcat8.0 一.pom包配置 <parent> ...
- "添加与删除程序"报rundll32错误
无法启动"添加与删除程序"系统报rundll32错误 系统反馈以下信息: rundll32.exe应用程序错误"0x00310030"指令 解决方法: 1.启动 ...
- Machine Learning - Andrew Ng - Coursera
Machine Learning - Andrew Ng - Coursera Contents 1 Notes 1 Notes What is Machine Learning? Two defin ...
- 守护进程,互斥锁,IPC,队列,生产者与消费者模型
小知识点:在子进程中不能使用input输入! 一.守护进程 守护进程表示一个进程b 守护另一个进程a 当被守护的进程结束后,那么守护进程b也跟着结束了 应用场景:之所以开子进程,是为了帮助主进程完成某 ...
- 对象new和不new的理解
1.现象 在一个线程类[QObject]中声明一个对象QTimer,[不new,直接声明],在槽函数中timer.start() 报警告:不能跨线程调用对象 2.分析 不使用new的方式,直接A a; ...
- java利用poi解析excel文件
首先需要引入以下jar包 如果使用maven,需要添加两个依赖 <dependencies> <dependency> <groupId>org.apache.po ...
- iOS开发 -------- 九宫格坐标计算
一 要求 完成下面的布局 二 分析 寻找规律,每一个UIView的x坐标和y坐标 三 实现思路 (1) 明确每一块用得是什么View; (2) 明确每个View之间的父子关系,每个视图都只有一个父视图 ...