标签:hdu
http://acm.hdu.edu.cn/showproblem.php?pid=3694

0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1
2.8284 0.0000
题意:给个四边形我,问一个点到四边形四个点距离最小的距离和是多少。
分析:如果是凸四边形,费马点就是对角线的交点,距离就是对角线长度。这个很好证明。。
如果是凹多边形,费马点就是那个凹点,看图:

首先CD上的任意点距离肯定大于D点的。然后对于任意点E,它的距离和大于F的。
一个是FA+FD+FC+FB 一个是EA+EB+ED+EC 由三角形两边和大于第三边EA+EB>FA+FB EA=EF+FA EF+EB>FB得证。。
具体实现的时候弱求了个凸包,由于有重点等的情况当凸包点数<=3时枚举的点求最小距离。
/**
* @author neko01
*/
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-8;
const double pi=acos(-1.0);
const int INF=0x7fffffff;
const LL inf=(((LL)1)<<61)+5;
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
if(x>0) return 1;
return -1;
}
struct point{
double x,y;
point(double x=0,double y=0):x(x),y(y) {}
};
point operator +(const point &a,const point &b){
return point(a.x+b.x,a.y+b.y);
}
point operator -(const point &a,const point &b){
return point(a.x-b.x,a.y-b.y);
}
point operator *(const point &a,const double &p){
return point(a.x*p,a.y*p);
}
point operator /(const point &a,const double &p){
return point(a.x/p,a.y/p);
}
bool operator < (const point &a,const point &b){
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
double dot(point A,point B){
return A.x*B.x+A.y*B.y;
}
double cross(point A,point B){
return A.x*B.y-A.y*B.x;
}
double Length(point A){
return sqrt(dot(A,A));
}
int graham(point *p,int n,point *ch) //凸包
{
sort(p,p+n);
int m=0;
for(int i=0;i<n;i++)
{
while(m>1&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;i--)
{
while(m>k&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
if(n>1) m--;
return m;
}
int main()
{
point p[5],ch[5];
while(true)
{
for(int i=0;i<4;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[0].x==-1) break;
int m=graham(p,4,ch);
double ans=1.0*INF;
if(m<=3)
{
for(int i=0;i<4;i++)
{
double sum=0;
for(int j=0;j<4;j++)
{
if(j==i) continue;
sum+=Length(p[i]-p[j]);
}
if(sum<ans) ans=sum;
}
}
else ans=Length(ch[0]-ch[2])+Length(ch[1]-ch[3]);
printf("%.4lf\n",ans);
}
return 0;
}hdu3694 Fermat Point in Quadrangle 求四边形费马点
标签:hdu
原文地址:http://blog.csdn.net/neko01/article/details/40797101