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常用对象的属性
%常用对象的属性 %.figure %hf=figure; %get(hf); %改变颜色 set Color %set(hf,'Color','w'); %去掉默认的菜单 Menubar %set( ...
- 计蒜客--移除数组中的重复元素 (set)
给定一个升序排列的数组,去掉重复的数,并输出新的数组的长度. 例如:数组 A = \{1, 1, 2\}A={1,1,2},你的程序应该输出 22 即新数组的长度,新数组为 \{1, 2\}{1,2} ...
- windows与linux ping 显示的ip不一样
DNS修改了一下域名对应的IP后,域名不能访问了,我在windows下ping一下域名,IP没有变过来,还是老的IP.我在linux下又ping了一下域名,是换过了的.这个问题是由windows下的本 ...
- Django之MVC和MTV
一. MVC MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式: Model(模型)表示应用程序核心(比如数据库记录列表). ...
- 爬虫之牛掰的scrapy框架
一. Scrapy简介及安装 http://python.jobbole.com/86405/ Scrapy的详细介绍 1.简介 2.安装 1.window上安装: 先 ...
- Android Camera2 预览,拍照,人脸检测并实时展现
https://www.jianshu.com/p/5414ba2b5508 背景 最近需要做一个人脸检测并实时预览的功能.就是边检测人脸,边在预览界面上框出来. 当然本人并不是专门做 ...
- Linux学习笔记之Linux环境变量总结
0x00 概述 Linux是一个多用户多任务的操作系统,可以在Linux中为不同的用户设置不同的运行环境,具体做法是设置不同用户的环境变量. 0x01 Linux环境变量分类 按照生命周期来分,Lin ...
- php+redis,延迟任务 实现自动取消订单,自动完成订单
简单定时任务解决方案:使用redis的keyspace notifications(键失效后通知事件) 需要注意此功能是在redis 2.8版本以后推出的,因此你服务器上的reids最少要是2.8版本 ...
- VMware无法读取USB文件
今天碰到虚拟机内的Mac OS无法读取USB,经过一番查看,是Windows的服务里面的vmware usb arbitration service服务没有启动,再点击启动的时候,报错,提示本地文件找 ...
- linux command line send email
https://www.tecmint.com/send-email-attachment-from-linux-commandline/ https://stackoverflow.com/ques ...