注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU 1348  

2014-04-15 23:02:27|  分类: 计算几何 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Wall


Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K
(Java/Other)

Total Submission(s) : 21   Accepted Submission(s) : 7

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.


HDU  1348 - 983433479 - jet sky


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

Northeastern Europe 2001

 


#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int l;
const double P=3.1415926;


struct node
{
int x,y;
}a[1110],stack1[1110];


double distan(node a,node b)
{
return (double)sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y)*1.0);
}
double across(node a,node n1,node n2)// 为正时 "左转"
{
return (n1.x-a.x)*(n2.y-a.y) - (n1.y-a.y)*(n2.x-a.x);
}
bool cmp(node a1,node b1)
{
double k=across(a[0],a1,b1);
if(k>0) return true;
else if (k==0&&distan(a[0],a1)<distan(a[0],b1))
{
return true;
}
else return false;
}
void anglesort(int n)
{
int i,k=0;
node temp;
for(i=1;i<n;i++)
{
if(a[i].y<a[k].y||(a[i].y==a[k].y&&a[i].x<a[k].x))
k=i;
}
temp=a[0];
a[0]=a[k];
a[k]=temp;
sort(a+1,a+n,cmp);
}
double Graham(int n)
{
anglesort(n);
int i,head;
double sum=0;
a[n]=a[0];
stack1[0]=a[0];
stack1[1]=a[1];
head=1;
for(i=2;i<=n;i++)
{
while(head>=1 && (across(stack1[head-1],stack1[head],a[i])<=0)) head--;

stack1[++head]=a[i];
}
for(i=0;i<head;i++)
{
sum+=distan(stack1[i],stack1[i+1]);
//printf("%lf ",sum);
}
sum+=2*double(l)*P;//唯一的区别就是我们的那个外围变了啊!
return sum;
}
int main()
{
int i,n,T;
double xx;
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);
}
xx=Graham(n);
printf("%.0lf\n",xx);
if(T)
printf("\n");

}
return 0;
}



  评论这张
 
阅读(6)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017