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 ...
随机推荐
- GUI常用对话框4
%普通对话框 dialog %单击时会关闭当前窗口 %自定义 关于对话框 点击确定 关闭 h = dialog( ]); uicontrol( ], ... 'string','确定','Callba ...
- POJ 1330 Nearest Common Ancestors(LCA Tarjan算法)
题目链接:http://poj.org/problem?id=1330 题意:给定一个n个节点的有根树,以及树中的两个节点u,v,求u,v的最近公共祖先. 数据范围:n [2, 10000] 思路:从 ...
- php学习路线(转)
作者:Summer链接:https://www.zhihu.com/question/20034403/answer/135433912来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
- MyEclipse/Eclipse快捷键总结
MyEclipse/Eclipse快捷键 查找某个方法被谁调用:选中方法名,ctrl+shift+g 通过文件名称查找类或文件:ctrl+shift+r(Open Resource)
- Windbg解决系统蓝屏
win10企业版连续两天遭遇系统蓝屏, 今天就各种检查,准备好好地研究一下这个问题,以下是整个过程: 首先,找到系统蓝屏时的错误日志: [计算机] --> [管理] --> [系统工具] ...
- fjwc2019 D3T2 送分题
#185. 「2019冬令营提高组」送分题 这是原题..... P3615 如厕计划 手推一推你发现,显然男性不能多于女性. 然后你或许可以发现一个神奇的性质. 对于每个序列,我们记$M$为$1$,$ ...
- Spring Boot(十三):spring boot小技巧
Spring Boot(十三):spring boot小技巧 一.初始化数据 我们在做测试的时候经常需要初始化导入一些数据,如何来处理呢?会有两种选择,一种是使用Jpa,另外一种是Spring JDB ...
- java常用类-StringBuffer,Integer,Character
* StringBuffer: * 线程安全的可变字符串. * * StringBuffer和String的区别? * 前者长度和内容可变,后者不可变. * 如果使用前者做字符串的拼接,不会浪费太多的 ...
- Java常用API基础
1:打开帮助文档2:点击显示,找到索引,看到输入框3:你要学习什么内容,你就在框框里面输入什么内容 举例:Random4:看包 java.lang包下的类在使用的时候是不需要导包的5:看类的描述 Ra ...
- 鼠标滑轮事件QWheelEvent
一般鼠标滑轮事件会发出信号,参数是QWheelEvent,只需要新建槽函数,QWheelEvent作为参数. void myMouseWheelEvent(QWheelEvent* even) {)/ ...