HDU 3694Fermat Point in Quadrangle(三分 不过网上大多是费马点的题解)
来源:互联网 发布:国外期刊 数据库 编辑:程序博客网 时间:2024/06/13 09:36
Fermat Point in Quadrangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1545 Accepted Submission(s): 256
Problem Description
In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the total distance from the three vertices of the triangle to the point is the minimum. It is so named because this problem is first raised by Fermat in a private letter. In the following picture, P0 is the Fermat point. You may have already known the property that:
Alice and Bob are learning geometry. Recently they are studying about the Fermat Point.
Alice: I wonder whether there is a similar point for quadrangle.
Bob: I think there must exist one.
Alice: Then how to know where it is? How to prove?
Bob: I don’t know. Wait… the point may hold the similar property as the case in triangle.
Alice: It sounds reasonable. Why not use our computer to solve the problem? Find the Fermat point, and then verify your assumption.
Bob: A good idea.
So they ask you, the best programmer, to solve it. Find the Fermat point for a quadrangle, i.e. find a point such that the total distance from the four vertices of the quadrangle to that point is the minimum.
Alice and Bob are learning geometry. Recently they are studying about the Fermat Point.
Alice: I wonder whether there is a similar point for quadrangle.
Bob: I think there must exist one.
Alice: Then how to know where it is? How to prove?
Bob: I don’t know. Wait… the point may hold the similar property as the case in triangle.
Alice: It sounds reasonable. Why not use our computer to solve the problem? Find the Fermat point, and then verify your assumption.
Bob: A good idea.
So they ask you, the best programmer, to solve it. Find the Fermat point for a quadrangle, i.e. find a point such that the total distance from the four vertices of the quadrangle to that point is the minimum.
Input
The input contains no more than 1000 test cases.
Each test case is a single line which contains eight float numbers, and it is formatted as below:
x1 y1 x2 y2 x3 y3 x4 y4
xi, yi are the x- and y-coordinates of the ith vertices of a quadrangle. They are float numbers and satisfy 0 ≤ xi ≤ 1000 and 0 ≤ yi ≤ 1000 (i = 1, …, 4).
The input is ended by eight -1.
Each test case is a single line which contains eight float numbers, and it is formatted as below:
x1 y1 x2 y2 x3 y3 x4 y4
xi, yi are the x- and y-coordinates of the ith vertices of a quadrangle. They are float numbers and satisfy 0 ≤ xi ≤ 1000 and 0 ≤ yi ≤ 1000 (i = 1, …, 4).
The input is ended by eight -1.
Output
For each test case, find the Fermat point, and output the total distance from the four vertices to that point. The result should be rounded to four digits after the decimal point.
Sample Input
0 0 1 1 1 0 0 11 1 1 1 1 1 1 1-1 -1 -1 -1 -1 -1 -1 -1
Sample Output
2.82840.0000
Source
2010 Asia Fuzhou Regional Contest
题目大意:题目意思很简单,给你四个点,问你求一个点使得到四个顶点的距离最小。网上大多是费马点的解释方法,终于知道便利店选址还有一个数学方法就是费马点。。。开始看了时间,才给了1s,觉得应该会WA,或者会TLE。真没想到会A,不过计算几何费马点也得学习下,速度都不是一个档次的。
AC代码:
#include<iostream>#include<cstring>#include<string>#include<cmath>#include<cstdio>using namespace std;double eps=1e-7;double minx,maxx,miny,maxy; //记录边界大小,三分struct mq{ double x; double y;};mq node[4];double dis(double xx,double yy){ int i; double sum=0; for(i=0;i<4;i++) sum+=sqrt((xx-node[i].x)*(xx-node[i].x)+(yy-node[i].y)*(yy-node[i].y)); return sum;}double cal(double x) //x确定后,寻找y最小{ double ly,ry,midy,mimidy; ly=miny,ry=maxy; midy=(ly+ry)/2.0; while(ry-ly>eps) { midy=(ly+ry)/2.0,mimidy=(midy+ry)/2.0; if(dis(x,midy)<dis(x,mimidy)) ry=mimidy; else ly=midy; } return dis(x,midy);}int main(){ int i; while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&node[0].x,&node[0].y,&node[1].x,&node[1].y,&node[2].x,&node[2].y,&node[3].x,&node[3].y)) { if(node[0].x<0) break; minx=maxx=node[0].x,miny=maxy=node[0].y; for(i=1;i<4;i++) { if(node[i].x<minx) minx=node[i].x; if(node[i].x>maxx) maxx=node[i].x; if(node[i].y<miny) miny=node[i].y; if(node[i].y>maxy) maxy=node[i].y; } double lx,rx,midx,mimidx; lx=minx,rx=maxx; midx=(lx+rx)/2.0; while(rx-lx>eps) { midx=(lx+rx)/2.0,mimidx=(midx+rx)/2.0; if(cal(midx)<cal(mimidx)) rx=mimidx; else lx=midx; } double res=cal(midx); printf("%.4f\n",res); } return 0;}//515MS
- HDU 3694Fermat Point in Quadrangle(三分 不过网上大多是费马点的题解)
- Hdu 3694 Fermat Point in Quadrangle(三分)
- hdu 3694 Fermat Point in Quadrangle
- hdu 3694 Fermat Point in Quadrangle (数学)
- HDU 3694 Fermat Point in Quadrangle(四边形的费马点)
- poj 3990 Fermat Point in Quadrangle / hdu 3694
- HDU 3694 Fermat Point in Quadrangle (数学-费马点)
- HDU 3694 Fermat Point in Quadrangle (数学-费马点)
- HDU 3694 Fermat Point in Quadrangle (计算几何- 四边形的费马点)
- HDU 3694 Fermat Point in Quadrangle (费马定理求四边形的费马点)
- HDOJ 3694 Fermat Point in Quadrangle
- Fermat Point in Quadrangle POJ 3990 四边形的费马点 数学
- hdu3694 Fermat Point in Quadrangle 费马点
- 2010 Asia Fuzhou Regional Contest HDOJ 3694 Fermat Point in Quadrangle
- poj 3990 Fermat Point in Quadrangle 凸包和费马点
- HDU3694 Fermat Point in Quadrangle 多边形费马点结论
- UVALive 5102 Fermat Point in Quadrangle 极角排序+找距离二维坐标4个点最近的点
- HDU3694Fermat Point in Quadrangle
- ios开发-下拉刷新一个莫名其妙的错误
- poj 2262 Goldbach's Conjecture 【素数筛】
- 【rmzt:魔兽冰封王座主题】
- java类库原码分析---Integer
- 数位dp poj3286 How many 0's?
- HDU 3694Fermat Point in Quadrangle(三分 不过网上大多是费马点的题解)
- Java获取网页源代码
- 【Rails】有关TDD测试入门
- 大数减法
- 一个骰子,6面,1个面是 1, 2个面是2, 3个面是3,问平均掷多少次能使1、2、3都至少出现一次。
- 初段——2440地址空间理解和jlink烧写SRAM
- makefile 中常见变量及函数
- sizeof()的()中算术运算不改变变量的值
- 基于结构;基于对象;面向对象;基于接口四种C++编程思想的实例分析