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 凸包模板的更多相关文章

  1. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  2. hdu 1348(凸包)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. hdu 1348 Wall (凸包)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. 计算几何(凸包模板):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 ...

  5. hdu 2202 最大三角形_凸包模板

    题意:略 思路:直接套用凸包模板 #include <iostream> #include <cstdio> #include <cmath> #include & ...

  6. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

  7. HDU 1392 凸包

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. 凸包模板 POJ1873

    // 凸包模板 POJ1873 // n=15所以可以按位枚举求凸包,再记录数据 #include <iostream> #include <cstdio> #include ...

  9. HDU 4946 凸包

    给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...

随机推荐

  1. javaweb登录界面连接数据库

    实验关键截图 数据库界面 建表 2.登录界面 登陆失败 5 注册页面 5 注册成功 数据库截图

  2. 利用Spark-mllab进行聚类,分类,回归分析的代码实现(python)

    Spark作为一种开源集群计算环境,具有分布式的快速数据处理能力.而Spark中的Mllib定义了各种各样用于机器学习的数据结构以及算法.Python具有Spark的API.需要注意的是,Spark中 ...

  3. Moment-JavaScript 日期处理类库

    来源:http://momentjs.cn/ 日期格式化 moment().format('MMMM Do YYYY, h:mm:ss a'); // 二月 22日 2017, 4:04:26 下午 ...

  4. electron 大体结构

    1.Electron支持的平台: OS XWindowsLinux 2.一个标准的electron app包含的结构: Windows 或是 Linux中:electron/resources/app ...

  5. 大型运输行业实战_day02_2_数据模型建立

    1.模型分析 1.基本必备字段 id   state  type   createTime   updateTime 2.车票  :   车次   开始车站   到达车站   出发时间    票价   ...

  6. suse11 sp4(虚拟机) 能ping通主机,但是主机ping不通suse虚拟机

    sese的防火墙没关. 查看防火墙状态: rcSuSEfirewall2 status(必须是root账户,sudo都不行) 关闭防火墙:rcSuSEfirewall2 stop 事实上,防火墙有时候 ...

  7. 5.Longest Palindromic Substring (String; DP, KMP)

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  8. 【校招面试 之 C/C++】第25题 C++ 智能指针(一)之 auto_ptr

    1.智能指针背后的设计思想 我们先来看一个简单的例子: void remodel(std::string & str) { std::string * ps = new std::string ...

  9. Collections.shuffle()源码分析

    Java.util.Collections类下有一个静态的shuffle()方法,如下: 1)static void shuffle(List<?> list)  使用默认随机源对列表进行 ...

  10. AspectJ的XML方式完成AOP的开发之切入点的表达式

    1. 再配置切入点的时候,需要定义表达式,重点的格式如下:execution(public * *(..)),具体展开如下: * 切入点表达式的格式如下: * execution([修饰符] 返回值类 ...