hdu 1348【凸包模板】
#include<iostream>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1005;
const double eps=1e-8;
int T,n,r,w,top;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian a) const
{
return dian(x-a.x,y-a.y);
}
}p[N],s[N],d;
int cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
double dis(dian a,dian b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(const dian &a,const dian &b)
{
double ar=cj(a-d,b-d);
return (ar>0)||((ar==0)&&a.x<b.x);
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&r);
d.x=d.y=10000;top=0;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].x<d.x||(p[i].x==d.x&&p[i].y<d.y))
d=p[i],w=i;
}//cout<<endl<<d.x<<" "<<d.y<<endl;
n--;
for(int i=w;i<=n;i++)
p[i]=p[i+1];
sort(p+1,p+1+n,cmp);
// for(int i=1;i<=n;i++)
// printf("%f %f\n",p[i].x,p[i].y);
s[++top]=d,s[++top]=p[1];
for(int i=2;i<=n;i++)
{
while(top>1&&cj(s[top]-p[i],s[top-1]-p[i])>=0)
top--;
s[++top]=p[i];
}
double ans=2.0*3.1415926*(double)r;//cout<<ans<<endl;
s[0]=s[top];
for(int i=1;i<=top;i++)
ans+=dis(s[i-1],s[i]);//,cout<<s[i].x<<" "<<s[i].y<<endl;
printf("%.0lf\n",ans);
if(T)
puts("");
}
return 0;
}
hdu 1348【凸包模板】的更多相关文章
- hdu 1348 凸包模板
http://acm.hdu.edu.cn/showproblem.php?pid=1348 造城墙问题,求出凸包加上一圈圆的周长即可 凸包模板题 #include <cstdio> #i ...
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- hdu 1348(凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 计算几何(凸包模板):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 2202 最大三角形_凸包模板
题意:略 思路:直接套用凸包模板 #include <iostream> #include <cstdio> #include <cmath> #include & ...
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- HDU 1392 凸包
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 凸包模板 POJ1873
// 凸包模板 POJ1873 // n=15所以可以按位枚举求凸包,再记录数据 #include <iostream> #include <cstdio> #include ...
- HDU 4946 凸包
给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
随机推荐
- Linux下增加User及添加sudo权限
运行adduser username 会默认建立同名的user,group,同时会要求输入用户密码及一些属性,完成之后OK. sudo chmod +w /etc/sudoers vi /etc/su ...
- HDU 1669 二分图多重匹配+二分
Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- CodeForces 596B Wilbur and Array
简单题,一个一个操作,最后就是答案. #include<cstdio> #include<cstring> #include<cmath> #include< ...
- 开头第一篇Hello World
以前在折腾个人博客的时候,使用过的WordpPress.Z-Blog.Typecho建站程序,开头第一篇都是Hello World,作为程序员的社区,开头第一篇当然也要是Hello World! 一句 ...
- 基于gulp编写的一个简单实用的前端开发环境
自从Node.js出现以来,基于其的前端开发的工具框架也越来越多了,从Grunt到Gulp再到现在很火的WebPack,所有的这些新的东西的出现都极大的解放了我们在前端领域的开发,作为一个在前端领域里 ...
- Python开发的一个IDE推荐,Sublime Text 3
Sublime Text 3 官网下载地址为, LINK. 目前最新版本是3114. 这里转载泱泱长空的授权文件(注册码)文章[1],将几个可以用的注册码列举如下: 补充:2016.05 最近经过测试 ...
- Leetcode:search_insert_position
一. 题目 给定一个数组和要插入数的大小.求插入的位置. 二. 分析 太水,直接扫描.过--. class Solution { public: int searchInsert(in ...
- Linux如何更新软件源
Linux软件源的设置方法 1 打开数据源配置文件 vi /etc/apt/sources.list 添加相关的数据源,可以选择以下的数据源,不要写太多,否则会影响更新速度. 之后使用ap ...
- vue自定义轮播图组件 swiper
1.banner 组件 components/Banner.vue <!-- 轮播图 组件 --> <template> <div class="swiper- ...
- PHP记录商品历史纪录
/* 记录浏览历史 */ if (!empty($_COOKIE['history'])) { if(stripos($_COOKIE['history'].',',$goods_id.',')=== ...