HDU3694 Fermat Point in Quadrangle
2012-09-13 10:10
295 查看
原题传送:http://acm.hdu.edu.cn/showproblem.php?pid=3694
题意很简单,求平面四个点的费马点。
这道题直接枚举所有情况:
1.四个点独立不重叠,这种情况又分为两种情况:
a.四个点构成凸四边形,那么对角线交点就是费马点
b.四个点构成凹四边形,那么费马点肯定是凹的那个点 (因为漏了这个情况wa了10多次)
2.四个点中有重复的点,费马点就是重复的那个点
View Code
题意很简单,求平面四个点的费马点。
这道题直接枚举所有情况:
1.四个点独立不重叠,这种情况又分为两种情况:
a.四个点构成凸四边形,那么对角线交点就是费马点
b.四个点构成凹四边形,那么费马点肯定是凹的那个点 (因为漏了这个情况wa了10多次)
2.四个点中有重复的点,费马点就是重复的那个点
View Code
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define INF 10000000.0 const double eps = 1e-6; struct point{double x, y;}; inline double min(double a, double b){return a < b ? a : b;} inline double max(double a, double b){return a > b ? a : b;} bool inter(point a, point b, point c, point d) // 判相交 { if(min(a.x, b.x) > max(c.x, d.x) || min(a.y, b.y) > max(c.y, d.y) || min(c.x, d.x) > max(a.x, b.x) || min(c.y, d.y) > max(a.y, b.y) ) return 0; double h, i, j, k; h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x); j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x); k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x); return h * i <= eps && j * k <= eps; } double cal(point a, point b) // 计算两点距离 { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main() { point a, b, c, d; double len[20]; while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y)) { if(a.x == -1) break; for(int i = 1; i < 20; i ++) len[i] = INF; if(a.x == d.x && a.y == d.y) len[1] = cal(a, b) + cal(a, c); //a,d重合 else if(a.x == c.x && a.y == c.y) len[2] = cal(a, b) + cal(a, d); //a,c重合 else if(a.x == b.x && a.y == b.y) len[3] = cal(a, c) + cal(a, d); //a,b重合 else if(b.x == c.x && b.y == c.y) len[4] = cal(b, a) + cal(b, d); //b,c重合 else if(b.x == d.x && b.y == d.y) len[5] = cal(b, a) + cal(b, c); //b,d重合 else if(c.x == b.x && c.y == b.y) len[6] = cal(c, a) + cal(c, b); //c,d重合 else { if(inter(a, b, c, d)) //ab, cd相交 len[7] = cal(a, b) + cal(c, d); else if(inter(a, c, b, d)) //ac, bd相交 len[8] = cal(a, c) + cal(b, d); else if(inter(a, d, b, c)) //ad, bc相交 len[9] = cal(a, d) + cal(b, c); } len[10] = cal(a, b) + cal(a, c) + cal(a, d); // 处理凹多边形 len[11] = cal(b, a) + cal(b, c) + cal(b, d); len[12] = cal(c, a) + cal(c, b) + cal(c, d); len[13] = cal(d, a) + cal(d, b) + cal(d, c); double m = INF; for(int i = 1; i < 20; i ++) m = min(len[i], m); printf("%.4lf\n", m); } return 0; }
相关文章推荐
- HDU3694 Fermat Point in Quadrangle(求四边形费马点)
- HDU3694 Fermat Point in Quadrangle 多边形费马点结论
- 2010 Asia Fuzhou Regional Contest HDOJ 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 Fermat Point in Quadrangle (计算几何- 四边形的费马点)
- hdu 3694 Fermat Point in Quadrangle (数学)
- UVALive 5102 Fermat Point in Quadrangle 极角排序+找距离二维坐标4个点最近的点
- HDU 3694 Fermat Point in Quadrangle (计算几何- 四边形的费马点)
- UVALive 5102 Fermat Point in Quadrangle 极角排序+找距离二维坐标4个点近期的点
- HDOJ 3694 Fermat Point in Quadrangle
- hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1
- hdu 3694 Fermat Point in Quadrangle
- HDU 3694 Fermat Point in Quadrangle (费马定理求四边形的费马点)
- How to Configure Workflow Infrastructure 2013 in Sharepoint 2013
- Working Together: SQL Server 2008 R2 Reporting Services Integration in SharePoint 2010
- The database schema is too old to perform this operation in this SharePoint cluster. Please upgrade the database and...
- Point-In-Time recovery
- Enabling .NET 3.5 in SharePoint 2007 Sites, the Lazy Way{转载}