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个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
随机推荐
- scala 基本语法
1.对于一个二元数组,键值对(k,v) 用map的时候,要取第一个或者第二个元素,用 _1 或者 _2表示. scala> words.take(2)res40: Array[(String, ...
- print 不换行
[print 不换行] 参考:http://zhidao.baidu.com/link?url=-qC2RyT5_GWzW_N-SyqJYgegVt2sSXwmMWGvHfk_4MjErhm_Pj23 ...
- javascript 中 if (window != top) top.location.href = location.href;的意思
如果当前窗口不是顶级窗口,就强制修改为顶级窗口: 目的是为了不让别人用iframe嵌入你的页面
- Python3 exec 函数
Python3 exec 函数 Python3 内置函数 描述 exec 执行储存在字符串或文件中的 Python 语句,相比于 eval,exec可以执行更复杂的 Python 代码. 语法 以下 ...
- oracle在centos6.5安装
说明 很多操作是默认,具体定制另说. 安装 参考http://www.linuxidc.com/Linux/2014-02/97374p4.htm 这篇是上面那篇的整合版:http://www.cnb ...
- 230. Kth Smallest Element in a BST 找到bst中的第k小的元素
[抄题]: Given a binary search tree, write a function kthSmallest to find the kth smallest element in i ...
- springmvc将处理后的数据通过get方法传给页面时,可能会出现乱码。下面对于get请求中文参数出现乱码提出解决办法。
对于get请求中文参数出现乱码解决办法有两个: 1.修改tomcat配置文件(tomcat--->conf--->server.xml)添加编码与工程编码一致,如下: <Connec ...
- Spring框架的事务管理之基于AspectJ的注解方式(重点掌握,最简单的方式)
1. 步骤一:恢复转账的开发环境(具体开发环境实现见:https://www.cnblogs.com/wyhluckdog/p/10137283.html)2. 步骤二:applicationCont ...
- Ubuntu 下如何查看已安装的软件
1.查看安装的所有软件 dpkg -l 例如:dpkg -l | grep ftp <span style="font-size:18px;">:~$ dpkg -l ...
- html 5 如何限制上传的文件类型 (uploadifive)
可以直接设置input标签的accept属性来限制上传文件的类型 <input type="file" accept="application/msword&quo ...