Wall

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4903    Accepted Submission(s): 1419

Problem Description
Once
upon a time there was a greedy King who ordered his chief Architect to
build a wall around the King's castle. The King was so greedy, that he
would not listen to his Architect's proposals to build a beautiful brick
wall with a perfect shape and nice tall towers. Instead, he ordered to
build the wall around the whole castle using the least amount of stone
and labor, but demanded that the wall should not come closer to the
castle than a certain distance. If the King finds that the Architect has
used more resources to build the wall than it was absolutely necessary
to satisfy those requirements, then the Architect will loose his head.
Moreover, he demanded Architect to introduce at once a plan of the wall
listing the exact amount of resources that are needed to build the wall.
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.

 
Input
The
first line of the input file contains two integer numbers N and L
separated by a space. N (3 <= N <= 1000) is the number of vertices
in the King's castle, and L (1 <= L <= 1000) is the minimal
number of feet that King allows for the wall to come close to the
castle.

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.

 
Output
Write
to the output file the single number that represents the minimal
possible length of the wall in feet that could be built around the
castle to satisfy King's requirements. You must present the integer
number of feet to the King, because the floating numbers are not
invented yet. However, you must round the result in such a way, that it
is accurate to 8 inches (1 foot is equal to 12 inches), since the King
will not tolerate larger error in the estimates.

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.

 
Sample Input
1

9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200

 
Sample Output
1628
 
Source
 
题意:国王要在城堡外修一个外墙,这一个外墙要隔城堡至少m英尺,求修这个外墙需要的最小费用
分析:我们先要找到刚好囊括整个城堡的一个外墙,这里要利用凸包算法,然后加上一个圆的周长,这里利用的是Graham算法。下面是算法流程:
令p0为Q中Y-X(not X-Y)坐标排序下最小的点
 设<p1,p2,...pm>为对其余点按以p0为中心的极角逆时针排序所得的点集(如果有多个点有相同的极角,除了距p0最远的点外全部移除
 压p0进栈S
 压p1进栈S
 压p2进栈S
  for i ← 3 to m
  do while 由S的栈顶元素的下一个元素、S的栈顶元素以及pi构成的折线段不拐向左侧
      对S弹栈
      压pi进栈S
  return S;

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const double pi = atan(1.0)*;
const double eps = 1e-;
struct Point
{
double x,y;
} p[N]; double cross(Point a,Point b,Point c)
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double dis(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int n,m;
Point Stack[N];
int cmp(Point a,Point b){
if(cross(a,b,p[])>)
return ;
if(cross(a,b,p[])==&&dis(b,p[])-dis(a,p[])>eps)
return ;
return ;
}
int Graham()
{
int k = ;
for(int i=; i<n; i++)
{
if(p[k].y>p[i].y||((p[k].y==p[i].y)&&(p[k].x>p[i].x))) k=i;
}
swap(p[],p[k]);
int top=;
sort(p+,p+n,cmp);
Stack[]=p[];
Stack[]=p[];
Stack[]=p[];
for(int i=; i<n; i++)
{
while(top>=&&cross(p[i],Stack[top],Stack[top-])>=)
{
top--;
}
Stack[++top]=p[i];
}
return top;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%d%d",&n,&m);
for(int i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
double sum=;
int top = Graham();
for(int i=; i<=top; i++)
{
sum+=sqrt(dis(Stack[i],Stack[i-]));
}
///处理最后一个点和P0
sum+=sqrt(dis(Stack[],Stack[top]));
///加上圆
sum+=*pi*m;
printf("%.0lf\n",sum);
if(tcase) printf("\n");
}
return ;
}

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

  1. hdu 1348 凸包模板

    http://acm.hdu.edu.cn/showproblem.php?pid=1348 造城墙问题,求出凸包加上一圈圆的周长即可 凸包模板题 #include <cstdio> #i ...

  2. HDU 4946 凸包

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

  3. hdu 1348 (凸包求周长)

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

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

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

  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(计算几何,求凸包周长)

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

  9. hdu 1348 Wall (凸包模板)

    /* 题意: 求得n个点的凸包.然后求与凸包相距l的外圈的周长. 答案为n点的凸包周长加上半径为L的圆的周长 */ # include <stdio.h> # include <ma ...

随机推荐

  1. const在c/c++中的区别

    #include <iostream> using namespace std; int main() { ; ; }; ; i < sizeof array / sizeof *a ...

  2. java有几种对象(PO,VO,DAO,BO,POJO)

    首先,java有几种对象(PO,VO,DAO,BO,POJO) 一.PO:persistant object 持久对象,可以看成是与数据库中的表相映射的java对象.使用Hibernate来生成PO是 ...

  3. WCF 动态调用(动态创建实例接口)

    很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; usin ...

  4. bcc编译

    bcc编译,直接在docker里编,太方便:第一次深切体会到docker的强大: 1)下载bcc源码: 2) 把源码中的Dockerfile.ubuntu重命名为Dockerfile 3)sudo d ...

  5. Elasticsearch1.x 和Elasticsearch2.x 拼音分词插件lc-pinyin安装教程

    Elasticsearch1.x 基于lc-pinyin和ik分词实现 中文.拼音.同义词搜索 https://blog.csdn.net/chennanymy/article/category/60 ...

  6. ASP.NET页面之间传值Application(5)

    Application对象的作用范围是整个全局,也就是说对所有用户都有效.它在整个应用程序生命周期中都是有效的,类似于使用全局变量一样,所 以可以在不同页面中对它进行存取.它和Session变量的区别 ...

  7. hihocoder 后缀自动机专题

    一.后缀自动机基本概念的理解 1.首先后缀自动机的状态是由子串的endpos来决定的 子串的endpos是指一个子串可以在原字符串的哪些位置进行匹配, endpos构成的不同集合划分成不同的状态 关于 ...

  8. [bzoj4889] [Tjoi2017]不勤劳的图书管理员

    Description 加里敦大学有个帝国图书馆,小豆是图书馆阅览室的一个书籍管理员.他的任务是把书排成有序的,所以无序的书让他产生厌烦,两本乱序的书会让小豆产生这两本书页数的和的厌烦度.现在有n本被 ...

  9. BZOJ4569 [SCOI2016]萌萌哒 【并查集 + 倍增】

    题目链接 BZOJ4569 题解 倍增的思想很棒 题目实际上就是每次让我们合并两个区间对应位置的数,最后的答案\(ans = 9 \times 10^{tot - 1}\),\(tot\)是联通块数, ...

  10. [WC2007]剪刀石头布——费用流

    比较有思维含量的一道题 题意:给混合完全图定向(定向为竞赛图)使得有最多的三元环 三元环条件要求比较高,还不容易分开处理. 正难则反 考虑,什么情况下,三元组不是三元环 一定是一个点有2个入度,一个点 ...