#include<iostream>
#include<cmath>//用了double型的凸包模版就华丽丽的A了
#include<algorithm>
#include<cstring>
#define PI acos(-1.0)
using namespace std;
const double eps = 1e-6;
int sgn(double a) {
return (a>eps) - (a<-eps);
}
struct point{
double x,y;
point (double xx=0,double yy=0)
{ //构造函数
x=xx; y=yy;
}
point operator -(point b){
return point(x-b.x,y-b.y);
}
double operator *(point b){
return (x*b.y-y*b.x);
}
double len(){
return sqrt(x*x+y*y);
}
void input(){
scanf("%lf%lf",&x,&y);
}
}p[102];
int stack[102],top;
int cmp(const void *a,const void *b) //逆时针排序 返回正数要交换
{
struct point *c=(struct point *)a;
struct point *d=(struct point *)b;
double k=(*c-p[0])*(*d-p[0]);
if(sgn(k)<0) return 1;
else if(sgn(k)==0 && sgn((*c-p[0]).len()-(*d-p[0]).len())>=0)
return 1;
else return -1;
}
void graham(int n) //形成凸包
{
int i;
for(i=0;i<=2;i++)
stack[i]=i;
top=2;
for(i=3;i<n;i++)
{
while( sgn((p[i]-p[stack[top-1]])*(p[stack[top]]-p[stack[top-1]])) > 0){
top--;
if(top==0) break;
}
top++;
stack[top]=i;
}
}
int main()
{
int n,i;
double sum;
int cas;
cin>>cas;
for(int kcas=1;kcas<=cas;kcas++)
{
double D;
cin>>n>>D;
for(i=0;i<n;i++)
p[i].input();
if(n==1){
cout<<"Case #"<<kcas<<": ";
printf("0.00\n");
continue;
}
if(n==2){
cout<<"Case #"<<kcas<<": ";
printf("%.4lf\n",2*(p[0]-p[1]).len()/acos(-1.0)/D);
continue;
}
int u=0;
for(i=1;i<n;i++) //找左下角的点
if(p[i].y<p[u].y || (p[i].y==p[u].y&&p[i].x<p[u].x) )
u=i;
//swap
point tmp=p[0];
p[0]=p[u];
p[u]=tmp;
qsort(p+1,n-1,sizeof(p[0]),cmp);
graham(n);
sum=0;
for(i=0;i<=top;i++)
sum+=(p[stack[i]]-p[stack[(i+1)%(top+1)]]).len();
cout<<"Case #"<<kcas<<": ";
printf("%.4lf\n",sum/acos(-1.0)/D);
}
return 0;
}
HDU4978
最新推荐文章于 2017-10-18 17:19:00 发布