Enclose--凸包

Description

There are n circles in a plane with equal radius. Now we wanna draw ashortest enclosed curve, and every circles lie in this curve. You have to writea program to calculate the length of this curve.

Input Description
The input contains multiple testcases.
For each case, the first line contains two integer n and r (1 ≤ n≤ 10000) denoting the number of circles and the radius of them. After that there aren lines, each line contains two integers denoting the coordinate of each circle.The absolute value of then would not be greater then 10000, and the radius is no large than 10000.
Output Description
For each case output one real number (round to 0.01) which is the length of that curve.
Sample Input
2 1
-1 0
1 0
5 1
1 0
0 1
-1 0
0 -1
0 0
Sample Output
10.28
11.94
 
真心无语了。。选拔赛的时候我带的模板中还有这道题呢。。我卡在那树深度的那道题。唉唉唉
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define pi acos(-1.0);
struct Point
{
	int x,y;
}point[50008],res[50008];
bool cmp(Point a,Point b)
{
	if(a.x<b.x)return 1;
	if(a.x>b.x)return 0;
	if(a.x==b.x)return a.y>b.y?0:1;
}
bool ral(Point p1,Point p2,Point p3)
{
	if((p3.y-p1.y)*(p2.x-p1.x)>(p3.x-p1.x)*(p2.y-p1.y))return 1;
	return 0;
}
double qlen(Point a,Point b)
{
	return sqrt(double((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x)));
}
int main()
{
	int n,r;
	while(scanf("%d%d",&n,&r)==2)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&point[i].x,&point[i].y);
		}
		sort(point,point+n,cmp);
		int m=-1;
		for(int i=0;i<n;i++)
		{
			while(m>=1&&!ral(res[m-1],res[m],point[i]))
			{
				m--;
			}
			res[++m]=point[i];
		}
		int k=m;
		for(int i=n-2;i>=0;i--)
		{
			while(k>m&&!ral(res[k-1],res[k],point[i]))
			{
				k--;
			}
			res[++k]=point[i];
		}
		double sum=0;
		sum=2*r*pi;
		for(int i=0;i<k;i++)
		{
			sum+=qlen(res[i],res[i+1]);
		}
		printf("%.2lf\n",sum);//这里不能用llf
	}
	return 0;
}
		

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值