HDU 1392 凸包
Surround the Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10345 Accepted Submission(s): 4009
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.
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
};
typedef point vec;
vec operator -(point a,point b)
{
return vec(a.x-b.x,a.y-b.y);
}
vec operator +(point a,point b)
{
return vec(a.x+b.x,a.y+b.y);
}
vec operator *(point a,double t)
{
return vec(a.x*t,a.y*t);
}
vec operator /(point a,double t)
{
return vec(a.x/t,a.y/t);
}
int dcmp(double x)
{
if(fabs(x)<=eps) return ;
return x<?-:;
}
double cross(vec a,vec b) ///叉积
{
return a.x*b.y-a.y*b.x;
}
bool cmp(point a,point b)
{
if(fabs(a.x-b.x)<=eps) return a.y<b.y;
return a.x<b.x;
}
double disn(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
/*两点之间的距离*/
}
void convexhull(point *s,int &n)
{
sort(s,s+n,cmp);
int m=;
point p[];
for(int i=; i<n; i++)
{
while(m> && dcmp(cross(p[m-]-p[m-],s[i]-p[m-]))<=)
m--;
p[m++]=s[i];
}
int k=m;
for(int i=n-; i>=; i--)
{
while(m>k && dcmp(cross(p[m-]-p[m-],s[i]-p[m-]))<=)
m--;
p[m++]=s[i];
}
m--;
n=m;
for(int i=; i<n; i++) s[i]=p[i];
/*建立凸包*/
}
int jishu;
int main()
{
while(scanf("%d",&jishu)!=EOF)
{
if(jishu==)
break;
point s[];
for(int i=; i<jishu; i++)
{
scanf("%lf %lf",&s[i].x,&s[i].y); }
if(jishu==)
{
printf("0.00\n");
continue;
}
if(jishu==)
{
printf("%.2f\n",disn(s[],s[]));
continue;
}
convexhull(s,jishu);
double sum=;
for(int i=; i<jishu-; i++)
{
sum+=disn(s[i],s[i+]);
}
sum+=disn(s[jishu-],s[]);
printf("%.2f\n",sum);
}
return ;
}
HDU 1392 凸包的更多相关文章
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- hdu 1392凸包周长
//用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...
- HDU - 1392 凸包求周长(模板题)【Andrew】
<题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...
- Surround the Trees HDU 1392 凸包
Problem Description There are a lot of trees in an area. A peasant wants to buy a rope to surround a ...
- 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 (凸包周长)
题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...
- HDU 4946 凸包
给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- No suitable driver found for jdbc:mysql://localhost/dbname
把mysql-connector-java的jar包放入jdk/jre/lib/ext文件下
- Fair Photography
题目大意: 给出直线上N个点的位置和颜色(0或1),求最大的区间,使得区间内0的个数大于等于1的个数且0的个数减去1的个数为偶数. 解题过程: 1.先贴个lsdsjy大牛的线段树的做法:http:// ...
- ROS创建工作空间(三)
查看正在使用的ROS工作空间,使用命令 echo $ROS_PACKAGE_PATH 我新建了两个
- 精通JS 笔记
一,javascript数据类型:undefined,null,boolean,number,string,object 五种加一种复杂类型. 注意大小写,区分大不写函数:functiontypeof ...
- lucene 查询的使用
各种查询方式一:使用QueryParser与查询语法.(会使用分词器) MultiFieldQueryParser查询字符串 ------------------------> Query对象 ...
- 反Secure Boot垄断:兼谈如何在Windows 8电脑上安装Linux
感谢HQSQ的投递一.自由软件基金会的呼吁上周,2012年将近结束的时候,自由软件基金会(FSF)发出呼吁,要求人们继续支持反Secure Boot垄断,希望签名者能达到5万人(目前是4万).我觉得, ...
- 登陆sqlserver及修改端口号 (转)
在一台计算机上面同时安装两个sql server数据库实例,第一次安装默认为机器名,端口号为1433 1.如果不知道服务器名,却想登陆的话可以直接输入127.0.0.1登陆之后,在新建查询中输入:SE ...
- RelativeLayout相对布局中拖放控件的办法
相对布局中拖了一个控件以后,要拖放第二个空间,死活拖不进去.仔细查看了鼠标的状况,发现要把第二个控件拖到第一个控件的周围,才能成功.果然是相对布局.
- php的数据访问
方法一:过去时方法 $定义一个变量 = $mysql_connect("要连接的服务器,默认是 localhost","登录所使用的用户名,默认是 root", ...
- 【模块应用】MFRC522开发笔记
一.了解基本概念 ①ISO-14443A协议:( 国际标准化组织:International Organization for Standardization)RFID协议的一种; PICC:临近 ...