hdu 1348 凸包模板
http://acm.hdu.edu.cn/showproblem.php?pid=1348
造城墙问题,求出凸包加上一圈圆的周长即可
凸包模板题
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
const int modo = 1e9 + 7;
const int maxn = 1e4 + 5;
struct point{
int x,y;
}a[maxn];
int b[maxn];
bool cmp(point a,point b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
double dis(point a,point b)
{
return sqrt(double((a.x-b.x)*(a.x-b.x)) + double((a.y - b.y)*(a.y - b.y)));
}
int cj(point a,point b,point c)
{
return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) *(b.x - c.x);
}
int m;
void graham(int n)
{
sort(a,a+n,cmp);
b[0] = 0,b[1] = 1,b[2] = 2;
int k = 1;
for(int i = 2;i < n;++i){
while(k && cj(a[i],a[b[k]],a[b[k-1]]) >= 0)
--k;
b[++k] = i;
}
m = k;
b[++k] = n - 2;
for(int i = n - 3;i >= 0;--i){
while(k != m && cj(a[i],a[b[k]],a[b[k-1]]) >= 0)
--k;
b[++k] = i;
}
m = k;
}
int main() {
int n,_;double f;
RD(_);
while(_--){
RD(n);
scanf("%lf",&f);
for(int i = 0;i < n;++i){
RD2(a[i].x,a[i].y);
}
graham(n);
double ans = 0;
for(int i = 0;i < m;++i)
ans += dis(a[b[i]],a[b[i+1]]);
ans += dis(a[b[m]],a[b[0]]);
ans += pi * 2 *f;
printf("%.0lf\n",ans);
if(_>0)
puts("");
}
return 0;
}
hdu 1348 凸包模板的更多相关文章
- 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个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
随机推荐
- delphi 图片加水印源代码
unit UWaterMark; interface uses {$IFNDEF DELPHIXE2ANDUP} windows,SysUtils,classes,graphics,Gdiplus; ...
- 在windows 2008 R2中SQl Server 2008中代理启动失败的一个原因总结
启动SQL代理的时候报错如下: 关调用实时(JIT)调试而不是此对话框的详细信息,请参见此消息的结尾. ************** 异常文本 **************System.NullRef ...
- 八大排序算法python实现
一.概述 排序有内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 我们这里说说八大排序就是内部排序. 当 ...
- python中迭代器(转)
一.迭代器与for语句 网上许多文章说Python的for语句中,in关键字后面的对象是一个集合.例如 for i in [1,2,3] print i 上面代码中in关键字后面的对象[1,2,3]是 ...
- afinal框架下 ViewInject的使用
1.可以在BaseActivity界面onCreate 方法setContentView后加上该语句. initInjectedView(this); 2.@ViewInject(id=R.id.v_ ...
- Element div is not closed
报错内容:Element div is not closed 解决方法: 将代码复制到NotePad++.SubLime Text等文本编辑器中,另存为.jsp或者.html文件. 这样可以利用语法高 ...
- iOS 静态库的封装
参考网址:http://www.jianshu.com/p/b754709135fb http://www.jianshu.com/p/443a5b8f3894 注意:封装静态库时要注意的地方: ...
- 关于block元素和inline元素
呃...这个会不会太基础了.最近在复习,所以基础知识也不能够忽略. 根据HTML 4.01 规范,其描述如下(http://www.w3.org/TR/html401/struct/global.ht ...
- 关于session报错问题。
刚开始一直报500错误,页面不提示,也没想着去查看日志文件.好几天了,一看日志,发现是这个问题.问了一下,是session的问题. 2017/07/25 16:57:49 [error] 2300#0 ...
- linux-git服务搭建
第一步,安装git: 源码安装参考:http://www.cnblogs.com/syuf/p/9151115.html 第二步,创建一个git用户,用来运行git服务: $ sudo adduser ...