/*
题意: 求得n个点的凸包。然后求与凸包相距l的外圈的周长。 答案为n点的凸包周长加上半径为L的圆的周长 */
# include <stdio.h>
# include <math.h>
# include <string.h>
# include <algorithm>
using namespace std;
# define PI acos(-1.0)
struct node
{
int x;
int y;
};
node a[1010],res[1010];
bool cmp(node a1,node a2)
{
if(a1.x==a2.x)
return a1.y<a2.y;
return a1.x<a2.x;
}
int cross(node a1,node a2,node a3)
{
return (a1.x-a3.x)*(a2.y-a3.y)-(a2.x-a3.x)*(a1.y-a3.y);
}
int convex(int n)//求凸包上的点
{
int m=0,i,j,k;
sort(a,a+n,cmp);
//求得下凸包。逆时针
//已知凸包点m个。假设新增加点为i。则向量(m-2,i)必然要在(m-2,m-1)的逆时针方向才符合凸包的性质
//若不成立。则m-1点不在凸包上。
for(i=0;i<n;i++)
{
while(m>1&&cross(res[m-1],a[i],res[m-2])<=0)
m--;
res[m++]=a[i];
}
k=m;
//求得上凸包
for(i=n-2;i>=0;i--)
{
while(m>k&&cross(res[m-1],a[i],res[m-2])<=0)
m--;
res[m++]=a[i];
}
if(n>1)
m--;
return m;
}
double length(node a1,node a2)
{
return sqrt(1.0*(a1.x-a2.x)*(a1.x-a2.x)+(a1.y-a2.y)*(a1.y-a2.y));
}
int main()
{
int t,n,i,L,m;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d%d",&n,&L);
for(i=0;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
m=convex(n);
double ans=0;
for(i=1;i<m;i++)
ans+=length(res[i],res[i-1]);
ans+=length(res[0],res[m-1]);
ans+=2*PI*L;
printf("%.0lf\n",ans);
if(t)
printf("\n");
}
}
return 0;
}

hdu 1348 Wall (凸包模板)的更多相关文章

  1. hdu 1348 Wall (凸包)

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

  2. hdu 1348【凸包模板】

    #include<iostream> #include<iostream> #include<algorithm> #include<cmath> us ...

  3. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. hdu 1348 (凸包求周长)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  5. POJ 1113 || HDU 1348: wall(凸包问题)

    传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  6. hdu 1348:Wall(计算几何,求凸包周长)

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

  7. HDU 1348 Wall 【凸包】

    <题目链接> 题目大意: 给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入. 解题分析: 求 ...

  8. HDU 1348 Wall ( 凸包周长 )

    链接:传送门 题意:给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入 思路:城墙与城堡直线长度是相等的, ...

  9. HDU 1348 Wall

    题解:计算凸包周长 #include <iostream> #include <cmath> #include <algorithm> const int size ...

随机推荐

  1. Spring Mvc中@ResponseBody中文乱码解决,以及修改返回的Content-Type

    http://www.codeif.com/topic/784 spring 3 mvc 的 @ResponseBody返回数据用起来很方便,但是中文乱码,而且返回的Content-Type不带编码信 ...

  2. 如何设置Google Chrome的界面显示语言

    昨天不小心,把Chrome浏览器的界面语言换成了中文, 结果换不回去英文了!!! 这是为啥呀? 我本来使用的是英文界面,换成中文却不让换回原来的语言,这怎么也说不过去吧. Google了一会子也没找到 ...

  3. shell字符串变量的特异功能:字符串的替换(${str/源模式/目标模式},${str//源模式/目标模式})、截断

    https://blog.csdn.net/wzb56_earl/article/details/6953612

  4. [BZOJ1494][NOI2007]生成树计数 状压dp 并查集

    1494: [NOI2007]生成树计数 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 793  Solved: 451[Submit][Status][ ...

  5. IE添加可信任站点,启用ActiveX插件批处理

    添加可信任站点IP地址为:192.168.1.108,启用ActiveX插件执行以下批处理命令: reg add "HKCU\Software\Microsoft\Windows\Curre ...

  6. 谜题15:令人晕头转向的Hello

    下面的程序是对一个老生常谈的例子做出了稍许的变化之后的版本.那么,它会打印出什么呢? /** * Generated by the IBM IDL-to-Java compiler, version ...

  7. 【kd-tree】bzoj4066 简单题

    同p1176. #include<cstdio> #include<cmath> #include<algorithm> using namespace std; ...

  8. 1.4(Spring学习笔记)Spring-JDBC基础

    一.Spring JDBC相关类 1.1 DriverManagerDataSource DriverManagerDataSource主要包含数据库连接地址,用户名,密码. 属性及含义如下配置所示: ...

  9. 一个强大的UI node 抽象

    基于cocos2d -x的一个强大的 界面对象的基类 ---@type uinode ui 对象的抽象 --@usage -- 界面打开的执行流程 -- 带*的是可选重写的函数,不带*的为必须实现的 ...

  10. Spring整合jdbc-jdbc模板api详解

    1, package com.songyan.jdbc2; public class User { private int id; private String name; public int ge ...