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个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
随机推荐
- C. Nearest vectors--cf598C(极角排序)
http://codeforces.com/problemset/problem/598/C 题目大意: 给你你个向量 向量的起点都是从(0,0)开始的 求哪个角最小 输出这两个向量 这是第一 ...
- google --SwitchyOmega and switchysharp ***
https://github.com/FelisCatus https://chrome.google.com/webstore/search/Proxy%20SwitchySharp%20?hl=z ...
- eclipse发布项目到tomcat部署目录
1.在eclipse下建立Dynamic Web Project工程zhgy,在使用eclipse中new一个tomcat,通过启动该tomcat来发布Dynamic Web Project的时候,其 ...
- MD5加密Java工具类
原文:http://www.open-open.com/code/view/1421764946296 import java.security.MessageDigest; public class ...
- 聊聊高并发(四十)解析java.util.concurrent各个组件(十六) ThreadPoolExecutor源代码分析
ThreadPoolExecutor是Executor运行框架最重要的一个实现类.提供了线程池管理和任务管理是两个最主要的能力.这篇通过分析ThreadPoolExecutor的源代码来看看怎样设计和 ...
- redis connetced refused remote
239down vote I've been stuck with the same issue, and the preceding answer did not help me (albeit w ...
- webpack-Manifest
Manifest 在使用 webpack 构建的典型应用程序或站点中,有三种主要的代码类型: 你或你的团队编写的源码. 你的源码会依赖的任何第三方的 library 或 "vendor&qu ...
- js 计算两个日期之间 相差几年几月几日
1.计算日期差 Mine.vue <!-- 我的 --> <template> <div> <!-- 标题栏 --> <x-header :lef ...
- uva live 4394 String painter 区间dp
// uva live 4394 String painter // // 这一题是训练指南上dp专题的习题,初看之下认为仅仅是稍微复杂了一点 // 就敲阿敲阿敲,两个半小时后,发现例子过了.然而自己 ...
- STL vector的介绍(1)
尝试下翻译STL里面的一些easy和算法.四级过了.六级刚考.顺便练练自己的英语水平.翻译的不好的地方请大神多多不吝赐教哈.方便我改正. 原来均来自:http://www.cplusplus.com/ ...