hdu 1348 Wall (凸包)
Wall
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3139 Accepted Submission(s): 888
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.

The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
简单凸包,题意和我的想法有点出入,既然是要求最小的长度,就不是简单的凸包可以解决的,额,忽略细节的话就是凸包模板题。
求凸包的长度+半径为L的圆的周长。
//31MS 256K 1479B G++
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 1005
#define pi 3.1415926
struct node{
double x,y;
}p[N],stack[N];
double dist(node a,node b)
{
return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));
}
double crossprod(node a,node b,node c)
{
return ((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y))/;
}
int cmp(const void*a,const void*b)
{
node c=*(node*)a;
node d=*(node*)b;
double k=crossprod(p[],c,d);
if(k< || !k && dist(p[],c)>dist(p[],d))
return ;
return -;
}
double graham(int n)
{
for(int i=;i<n;i++)
if(p[i].x<p[].x || p[i].x==p[].x && p[i].y<p[].y){
node temp=p[];
p[]=p[i];
p[i]=temp;
}
qsort(p+,n-,sizeof(p[]),cmp);
p[n]=p[];
for(int i=;i<;i++) stack[i]=p[i];
int top=;
for(int i=;i<n;i++){
while(crossprod(stack[top-],stack[top],p[i])<= && top>=)
top--;
stack[++top]=p[i];
}
double ans=dist(stack[],stack[top]);
for(int i=;i<top;i++)
ans+=dist(stack[i],stack[i+]);
return ans;
}
int main(void)
{
int t,n;
double l;
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&n,&l);
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double ans=*l*pi;
ans+=graham(n);
printf("%.0lf\n",ans);
if(t) printf("\n");
}
return ;
}
hdu 1348 Wall (凸包)的更多相关文章
- hdu 1348 Wall (凸包模板)
/* 题意: 求得n个点的凸包.然后求与凸包相距l的外圈的周长. 答案为n点的凸包周长加上半径为L的圆的周长 */ # include <stdio.h> # include <ma ...
- 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 ...
- hdu 1348【凸包模板】
#include<iostream> #include<iostream> #include<algorithm> #include<cmath> us ...
随机推荐
- 怎样创建FTP服务器
怎样创建FTP服务器 2008-05-06 08:42永远的探索|分类:操作系统/系统故障| 浏览6382次 我准备用局域网内的一台机器做FTP服务器,创建FTP服务器一定要用Windows serv ...
- DB_MYSQL_mysql-5.7.10-winx64解压版安装笔记
1.http://dev.mysql.com/downloads/mysql/ 里面下载Windows (x86, 64-bit), ZIP Archive mysql-5.7.10-winx64.z ...
- JsonResult序列化并保存json文件 以及对json文件读取反序列
项目中我们经常遇到一些经常访问的接口,并且更新及时度不是特别高,那么我们可以利用文件来做一些数据请求的缓存. 这里以微信公众号获取粉丝用户列表为例,我们把微信公众号查到的用户先缓存在文件中,这样在翻页 ...
- 解决jsp下载文件,迅雷下载路径不显示文件名称的问题
如果浏览器安装了迅雷的插件,在jsp页面调用java后台实现文件下载功能时,会自动弹出迅雷下载,迅雷的下载路径会显示.do或者.xhtml之类的,为了解决这个问题,jsp页面修改如下: 写一个< ...
- MYSQL C API : struct MYSQL_STMT 结构的组合使用
#include <iostream> #include <string> #include <string.h> #include <assert.h> ...
- 玩转单元测试之Testing Spring MVC Controllers
玩转单元测试之 Testing Spring MVC Controllers 转载注明出处:http://www.cnblogs.com/wade-xu/p/4311657.html The Spri ...
- UNIX网络编程-recv、send、read、write之间的联系与区别
1.read ----------------------------------------------------------------------- #include <unistd.h ...
- C/C++中的指针数组和数组指针
1. 指针数组 定义:int *p[n],由于[]的优先级高于*,p和[]结合成一个数组,该数组的元素存储的是int类型的指针,由于数组内容是指针,因此p+1的步长是sizeof(int*),在32位 ...
- openldap主机访问控制(基于hostname)
http://mayiwei.com/2013/03/21/centos6-openldap/ http://www.zytrax.com/books/ldap/ch11/dynamic.html h ...
- Mac后台开发MNMP(nginx , mysql, php)标配
mysql安装: 方法:1.原始方法,下载压缩文件,解压,安装,配置 2.dmp文件安装 3.brew安装 这里使用brew安装: a.brew ...