hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1
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
Each test case is a single line which contains eight float numbers, and it is formatted as below:
x 1 y 1 x 2 y 2 x 3 y 3 x 4 y 4
x i, y i are the x- and y-coordinates of the ith vertices of a quadrangle. They are float numbers and satisfy 0 ≤ x i ≤ 1000 and 0 ≤ y i ≤ 1000 (i = 1, …, 4).
The input is ended by eight -1.
Output
Sample Input
1 1 1 1 1 1 1 1
-1 -1 -1 -1 -1 -1 -1 -1
四边形费马点
平面四边形费马点证明图形
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; const double eps=1e-10; double add(double a,double b)
{
if(abs(a+b)<eps*(abs(a)+abs(b))) return 0;
return a+b;
} struct point
{
double x,y;
point () {}
point (double x,double y) : x(x),y(y){ }
point operator + (point p)
{
return point (add(x,p.x),add(y,p.y));
}
point operator - (point p)
{
return point (add(x,-p.x),add(y,-p.y));
}
point operator * (double d)
{
return point (x*d,y*d);
}
double dot(point p)
{
return add(x*p.x,y*p.y);
}
double det(point p)
{
return add(x*p.y,-y*p.x);
}
}; bool on_seg(point p1,point p2,point q)
{
return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
} point intersection(point p1,point p2,point q1,point q2)
{
return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
} bool cmp_x(const point&p,const point& q)
{
if(p.x!=q.x) return p.x<q.x;
return p.y<q.y;
} vector<point> convex_hull(point*ps,int n)
{
sort(ps,ps+n,cmp_x);
//for(int i=0;i<n;i++) printf("x=%.f %.f")
int k=0;
vector<point> qs(n*2);
for(int i=0;i<n;i++){
while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
qs[k++]=ps[i];
}
for(int i=n-2,t=k;i>=0;i--){
while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
qs[k++]=ps[i];
}
qs.resize(k-1);
return qs;
} double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
bool equ(point p1,point p2)
{
if(fabs(p1.x-p2.x)<eps&&fabs(p1.y-p2.y)<eps)
return true;
return false;
}
int main()
{
point p[10];
for(int i=0;i<4;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
while(p[0].x!=-1&&p[0].y!=-1)
{
vector <point> m;
double minn=100000000,d;
m=convex_hull(p,4);//检查是否四边形
if(m.size()==4)//如果是四边形则加入对角线交点考虑
minn=dis(m[1],m[3])+dis(m[0],m[2]);
for(int i=0;i<4;i++)
{
d=0;
for(int j=0;j<4;j++)
d+=dis(p[i],p[j]);
minn=min(minn,d);
}
printf("%.4f\n",minn);
for(int i=0;i<4;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
}
return 0;
}
hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1的更多相关文章
- hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1
F - Computer Virus on Planet Pandora Time Limit:2000MS Memory Limit:128000KB 64bit IO Format ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0
Description “Farm Game” is one of the most popular games in online community. In the community each ...
- hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1
C - To Be an Dream Architect Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
F - Rotational Painting Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0
C - To Be an Dream Architect Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 4770 13 杭州 现场 A - Lights Against Dudely 暴力 bfs 状态压缩DP 难度:1
Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money.&quo ...
随机推荐
- java 入门基础学习
问题一:java编写的源代码为什么能在windows/linux/macOS操作系统运行?运行原理是什么?为什么说它是跨平台的? 从jdk/jvm/jre说起 1.JDK简介 https://blog ...
- 洛谷P4428二进制 [BJOI2018] 线段树
正解:线段树 解题报告: 传送门! 话说开始看到这题的时候我想得hin简单 因为关于%3有个性质就是说一个数的各个位数之和%3=这个数%3嘛,小学基础知识? 我就想着,就直接建一棵树,只是这棵树要用个 ...
- api收录
ip地址查询api http://ip.taobao.com/service/getIpInfo.php?ip= 如: http://ip.taobao.com/service/getIpInfo.p ...
- mysql 数据操作 多表查询 子查询 介绍
子查询就是: 把一条sql语句放在一个括号里,当做另外一条sql语句查询条件使用 拿到这个结果以后 当做下一个sql语句查询条件mysql 数据操作 子查询 #1:子查询是将一个查询语句嵌套在另一个 ...
- centos LAMP第四部分mysql操作 忘记root密码 skip-innodb 配置慢查询日志 mysql常用操作 mysql常用操作 mysql备份与恢复 第二十二节课
centos LAMP第四部分mysql操作 忘记root密码 skip-innodb 配置慢查询日志 mysql常用操作 mysql常用操作 mysql备份与恢复 第二十二节课 mysq ...
- GraphQL:一种不同于REST的接口风格
从去年开始,JS算是完全踏入ES6时代.在React相关项目中接触到了一些ES6的语法.这次接着GraphQL这种新型的接口风格,从后端的角度接触ES6. 这篇文章从ES6的特征讲起,打好语法基础:然 ...
- 数据挖掘-逻辑Logistic回归
逻辑回归的基本过程:a建立回归或者分类模型--->b 建立代价函数 ---> c 优化方法迭代求出最优的模型参数 --->d 验证求解模型的好坏. 1.逻辑回归模型: 逻辑回归(L ...
- 'React/RCTBundleURLProvider.h' file not found
'React/RCTBundleURLProvider.h' file not found 新建RN项目时在iOS端用xcode跑时有时会遇到 'React/RCTBundleURLProvider. ...
- king 选 太子
king 选 太子 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 啊,从前有一个国家.此国兵强马壮,但是国王却身体不好.于是就想挑一位太子出来: 但是问题来了,国王 ...
- 根据Excel文件中的内容,修改指定文件夹下的文件名称
问题:根据Excel文件中内容,把文件名称由第2列,改为第1列.比如:把文件“123.jpg”修改为“1.jpg”.