hdu 1348 Wall (凸包模板)
/*
题意: 求得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 (凸包模板)的更多相关文章
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1348【凸包模板】
#include<iostream> #include<iostream> #include<algorithm> #include<cmath> us ...
- hdu 1348 Wall(凸包模板题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 1348 (凸包求周长)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) Mem ...
- POJ 1113 || HDU 1348: wall(凸包问题)
传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- hdu 1348:Wall(计算几何,求凸包周长)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1348 Wall 【凸包】
<题目链接> 题目大意: 给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入. 解题分析: 求 ...
- HDU 1348 Wall ( 凸包周长 )
链接:传送门 题意:给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入 思路:城墙与城堡直线长度是相等的, ...
- HDU 1348 Wall
题解:计算凸包周长 #include <iostream> #include <cmath> #include <algorithm> const int size ...
随机推荐
- Selenium2+python自动化60-异常后截图(screenshot)【转载】
前言 在执行用例过程中由于是无人值守的,用例运行报错的时候,我们希望能对当前屏幕截图,留下证据. 在写用例的时候,最后一步是断言,可以把截图的动作放在断言这里,那么如何在断言失败后截图呢? 一.截图方 ...
- js中的数组(类)的相加
var wcf=[1,2,3,4,5] console.log(wcf[4]) var wcf1=[7,8,9,10,11] var wcf2=wcf+wcf1 console.log(wcf2) c ...
- ASP.NET MVC中DropDownList的使用
Asp.net MVC中的DropDownLists貌似会让一开始从Asp.net Forms转过来的程序员造成不少迷惑.这篇文章讲述了为了使用DropDownLists,你需要在Asp.Net MV ...
- Python爬虫Scrapy测试
# -*- coding:utf- -*- import urllib import urllib2 import re import thread import time #糗事百科爬虫类 clas ...
- android 屏幕显示
一.像素 android 常用单位 px.dp.sp dp和sp只与屏幕的物理尺寸有关 dp和sp的区别: sp会随着系统字体的大小而改变,通常用来设置字体大小.dp不会随系统设置的字体改变 dp和p ...
- 百度MapAPI之地理编码
地理编码:将具体地址数据转换为对应坐标点经纬度功能 大致思路: 1.从数据库取得具体地理位置 2.将地址作为参数访问API接口,获取返回数据 3.处理response数据并将经度(lng.longit ...
- HDU 6315: Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- Python web 简单服务器的搭建与运行
搭建python的CGI环境: 假设在/var/www/cgi-bin下建立一个hello.py的文件 在ubuntu下打开终端 然后用命令 cd /var/www/ 进入后执行命令 : python ...
- 【二分答案】【最大流】bzoj3130 [Sdoi2013]费用流
二分最大的边的cap,记作Lim. 把所有的边的cap设为min(Lim,cap[i]). Bob一定会把单位费用加到最大边上. #include<cstdio> #include< ...
- 【状态压缩DP】BZOJ1087-[SCOI2005]互不侵犯King
[题目大意] 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. [思路] 先预处理每一行可行的状态 ...