码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3934 tomo

时间:2014-08-15 22:29:19      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   io   for   ar   art   html   

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define eps 1e-8
#define MAXX 1000010

typedef struct point
{
double x;
double y;
}point;

bool dy(double x,double y){ return x>y+eps; }
bool xy(double x,double y){ return x<y-eps; }
bool dyd(double x,double y){ return x>y-eps; }
bool xyd(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((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}

point c[MAXX];
point stk[MAXX];
int top;

bool cmp(point a,point b)
{
double len=crossProduct(c[0],a,b);
if(dd(len,0.0))
return xy(dist(c[0],a),dist(c[0],b));
return xy(len,0.0);
}

double max(double x,double y)
{
return xy(x,y) ? y : x;
}

void Graham(int n)
{
int tmp=0;
for(int i=1; i<n; i++)
{
if(xy(c[i].x,c[tmp].x) || dd(c[i].x,c[tmp].x) && xy(c[i].y,c[tmp].y))
tmp=i;
}
swap(c[0],c[tmp]);
sort(c+1,c+n,cmp);
stk[0]=c[0];
stk[1]=c[1];
top=1;
for(int i=2; i<n; i++)
{
while(top && dyd(crossProduct(c[i],stk[top],stk[top-1]),0.0))
top--;
stk[++top]=c[i];
}
}

double rotating(int n)
{
int j=1,k=2;
double ans=0.0;
c[n]=c[0];
for(int i=0; i<n; i++)
{
//j=(i+1)%n;
//k=(j+1)%n;
while(xy(fabs(crossProduct(c[i],c[j],c[k])),fabs(crossProduct(c[i],c[j],c[(k+1)%n]))))
k=(k+1)%n;
ans=max(ans,fabs(crossProduct(c[i],c[j],c[k])));
while(xy(fabs(crossProduct(c[i],c[j],c[k])),fabs(crossProduct(c[i],c[(j+1)%n],c[k]))))
j=(j+1)%n;
ans=max(ans,fabs(crossProduct(c[i],c[j],c[k])));
}
return ans*0.5;
}

int main()
{
int i,j,n;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; i++)
scanf("%lf%lf",&c[i].x,&c[i].y);
Graham(n);
double ans=rotating(top);
printf("%.2lf\n",ans);
}
return 0;
}

 

http://blog.csdn.net/crazy852456/article/details/10103873

http://www.cnblogs.com/devtang/archive/2012/03/03/2378339.html

hdu 3934 tomo,布布扣,bubuko.com

hdu 3934 tomo

标签:blog   http   os   io   for   ar   art   html   

原文地址:http://www.cnblogs.com/ccccnzb/p/3915757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!