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 ...
随机推荐
- [原创]cocos2d-x研习录-第二阶 概念类之精灵类(CCSprite)
上一节说布景层CCLayer是小容器,那么精灵类CCSprite就是容器添加的内容,它是构成游戏的主要元素.精灵这个名称应该是游戏专用,它表示游戏中玩家操作的主角.敌人.NPC(Non Player ...
- Appium自动化时,如何快速获得Android app的包名和启动页
在app自动化的时候,经常被问道如何知道app的包名和启动页名称.这个问题很简单: 1. 最直接的方式,去问开发啊,他们告诉你app的包名和启动页. 2. 如果你比较腼腆,又能看到/懂代码,自己把代码 ...
- Hibernate之mappedBy
Hibernate之mappedBy 摘要: 一.mappedBy单向关系不需要设置该属性,双向关系必须设置,避免双方都建立外键字段 数据库中1对多的关系,关联关系总是被多方维护的即外键建在多方,我们 ...
- Spring学习 Ioc篇(二 )
5.spring依赖注入的方式 方法一:使用构造器方式进行注入 1.dao的类和接口 package com.cvicse.dao.impl; import com.cvicse.dao.Person ...
- bzoj2515 Room
Description Input Output 折半搜索,用散列表记录从原点出发,用了S(状压表示)这几种边(令|S|*2-1<=n),到达(x,y)的最大面积. #include<cs ...
- Asp.net MVC 之过滤器
整理一下MVC中的几种过滤器,以及每种过滤器是干什么用的 四种过滤器 1.AuthorizationFilter(授权过滤器) 2.ActionFilter(方法过滤器) 3.ResultFilter ...
- server application error应用错误
本地使用IIS测试ASP脚本网页,结果发现提示[Server Application Error The server has encountered an error while loading a ...
- linux shell中的&& || 和()
1. linux命令返回值介绍 shell 在执行某个命令时,会有一个返回值,该值保存在shell变量$?中.当$?为0时,表示命令执行成功:当$?为1时,表示命令执行失败. 2. && ...
- 货币单位类RmbUnit
import java.math.BigDecimal; public enum RmbUnit { FEN{ public String toFen(String amt) { BigDecimal ...
- 基于案例贯通 Spark Streaming 流计算框架的运行源码
本期内容 : Spark Streaming+Spark SQL案例展示 基于案例贯穿Spark Streaming的运行源码 一. 案例代码阐述 : 在线动态计算电商中不同类别中最热门的商品排名,例 ...