链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348

Wall

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

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
 
----------------------------------------------------------------------
看了discuss,用了模板,然后做的这题
题目意思需要自己抽取出来,此题边界的四个角加起来是个圆,然后剩下的就是一个凸包的周长,然后就没什么了
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm> using namespace std; const int MAX=;
const double eps=1e-; typedef struct point
{
double x,y;
}point; point c[MAX];
int top; bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool xyd(double x,double y)
{
return x<y+eps;
}
bool dyd(double x,double y)
{
return x>y-eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} bool cmp(point a,point b)
{
if(dd(a.y,b.y))
{
return xy(a.x,b.x);
}
return xy(a.y,b.y);
}
bool cmp1(point a,point b)
{
double len=crossProduct(c[],a,b);
if(dd(len,0.0))
{
return xy(dist(c[],a),dist(c[],b));
}
return xy(len,0.0);
} point stk[MAX]; double dis()
{
double sum=0.0;
for(int i=;i<top;i++)
{
sum+=dist(stk[i],stk[i+]);
}
sum+=dist(stk[top],stk[]);
return sum;
} double Graham(int n)
{
sort(c,c+n,cmp);
sort(c+,c+n,cmp1);
top=;
stk[top++]=c[];
stk[top++]=c[];
stk[top++]=c[];
top--;
for(int i=;i<n;i++)
{
while()
{
point a,b;
a=stk[top];
b=stk[top-];
if(xyd(crossProduct(a,b,c[i]),0.0))
{
top--;
}
else
break;
}
stk[++top]=c[i];
}
return dis();
} int main()
{
int i,j,k,t;
int n,m;
int cas=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%lf%lf",&c[i].x,&c[i].y);
}
if(cas++)
{
printf("\n");
}
double re=*acos(0.0)*m;
double sum=Graham(n);
printf("%.0lf\n",sum+re);
}
}

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

  1. HDU - 1392 凸包求周长(模板题)【Andrew】

    <题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...

  2. TZOJ 2569 Wooden Fence(凸包求周长)

    描述 Did you ever wonder what happens to your money when you deposit them to a bank account? All banks ...

  3. zoj 1453 Surround the Trees(凸包求周长)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds      Memory ...

  4. hdu 1348 凸包模板

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

  5. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  6. hdu 1348(凸包)

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

  7. Surround the Trees(凸包求周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. HDU 4667 Building Fence(求凸包的周长)

    A - Building Fence Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u ...

  9. (hdu step 7.1.7)Wall(求凸包的周长——求将全部点围起来的最小凸多边形的周长)

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

随机推荐

  1. 根据linux内核源码查找recv返回EBADF(errno 9)的原因

    linux的内核版本是2.6.18,x86_64. man里的解释是: EBADF The argument s is an invalid descriptor 我的模拟测试环境是: 前端loadr ...

  2. mysql笔记02 创建高性能的索引

    创建高性能的索引 1. 索引(在MySQL中也叫做"键(key)")是存储引擎用于快速找到记录的一种数据结构. 2. 索引可以包含一个或多个列的值.如果索引包含多个列,那么列的顺序 ...

  3. Apache服务器访问过慢分析及解决

    起因:线上的一台服务器,最近总是出现 访问 很慢的情况发生,点击一个链接要2秒钟以上才能打开,按照我们对于访问人数的估计,服务器应该不至于响应这么慢,从而需要针对这个问题进行分析,来解决网站访问过慢. ...

  4. C# ZipHelper C#公共类 压缩和解压

    关于本文档的说明 本文档基于ICSharpCode.SharpZipLib.dll的封装,常用的解压和压缩方法都已经涵盖在内,都是经过项目实战积累下来的 1.基本介绍 由于项目中需要用到各种压缩将文件 ...

  5. [转]jexus的安装

    转自http://www.cnblogs.com/xiaodiejinghong/p/3720921.html 这是一个集成了 mono3.4.0 和 jexus5.6.0 的 jexus+mono ...

  6. PHP array_column() 函数

    定义和用法 array_column() 返回输入数组中某个单一列的值. array_column(array,column_key,index_key); 参数 描述 array 必需.规定要使用的 ...

  7. YTU 3005: 皇后问题(栈和队列)

    3005: 皇后问题(栈和队列) 时间限制: 1 Sec  内存限制: 128 MB 提交: 6  解决: 3 题目描述 编写一个函数,求解皇后问题:在n*n的方格棋盘上,放置n个皇后,要求每个皇后不 ...

  8. YTU 2925: 文件操作--文本文件读入

    2925: 文件操作--文本文件读入 时间限制: 1 Sec  内存限制: 128 MB 提交: 38  解决: 16 题目描述 现有100名学生的姓名(name).学号(num).英语(Englis ...

  9. ThreadLocal的使用及介绍

    ThreadLocal总结 1.ThreadLocal使用场合主要解决多线程中数据数据因并发产生不一致问题.ThreadLocal为每个线程的中并发访问的数据提供一个副本,通过访问副本来运行业务,这样 ...

  10. 20151124001 关闭C#主窗体弹出是否关闭对话框

    关闭C#主窗体弹出是否关闭对话框 private void Frm_Main_FormClosing(object sender, FormClosingEventArgs e)        {   ...