HDU 3458 Enumerate the Triangles(最小周长三角形)
来源:互联网 发布:尤氏 知乎 编辑:程序博客网 时间:2024/06/03 17:31
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3548
题意:
给定N个点的坐标求这些点能够成的周长最小的三角形的周长。
分析:
设三角形的三变长分别为,a,b,c; a<b+c;L=a+b+c;
因此当我们的当前的最小周长如果小于其中一条边的二倍的话
那么很明显有这个边构成的三角形的周长一定大于现在的周长,
我们可以根据这个性质进行减枝。
代码如下:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const int maxn = 1010;struct point{ double x,y; bool operator < (const struct point &tmp)const{ return x<tmp.x; }}p[maxn];inline double dis(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}inline bool check(point a,point b,point c){ if((a.x-b.x)*(c.y-b.y)==(a.y-b.y)*(c.x-b.x)) return false; return true;}int main(){ int n,t,cas=1; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); sort(p,p+n); bool f=0; double ans = 1000000000; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(ans <= 2*( p[j].x - p[i].x) )break; double dd =dis(p[i],p[j]); for(int k=j+1;k<n;k++){ if(ans<=2*(p[k].x-p[i].x)) break; if(check(p[i],p[j],p[k])){ f=1; if(ans>dis(p[i],p[k])+dis(p[j],p[k])+dd) ans = dis(p[i],p[k])+dis(p[j],p[k])+dd; } } } } if(f) printf("Case %d: %.3lf\n",cas++,ans); else printf("Case %d: No Solution\n",cas++); } return 0;}
0 0
- HDU 3458 Enumerate the Triangles(最小周长三角形)
- HDU 3548 Enumerate the Triangles(找周长最小的三角形)
- HDU 3548 Enumerate the Triangles(找周长最小的三角形+优化)
- hdu 3549 Enumerate the Triangles
- HDU NO.3548 Enumerate the Triangles
- hduoj 3548 Enumerate the Triangles
- hdu 3548 最小三角形周长(计算几何)
- HDU 5224(最小周长)
- Enumerate the Triangles&&http://cdn.ac.nbutoj.com/Contest/view/id/14/problem/E.xhtml
- 二分 点集中最近点对、周长最小三角形
- 三角形的数目 Count the number of possible triangles
- (hdu step 7.1.4)Surround the Trees(求凸包的周长——计算将所有点都包围起来的最小凸多边形的周长)
- 最小周长
- 最小周长
- POJ2242_The Circumference of the Circle(几何/三角形外接圆周长/模板)
- HDU 4486(周长确定三角形的个数统计 对比上次的互质三角形)
- 三角形周长与面积
- 最大周长三角形
- 独立开发者:新手做2D手游该用哪些工具?
- Java程序员从笨鸟到菜鸟之(四十八)细谈struts2(十)ognl概念和原理详解
- struts2开发环境中,enctype="multipart/form-data"上传文件时,request.getInputStream()为null的原因
- 无限的路
- Head First---状态模式
- HDU 3458 Enumerate the Triangles(最小周长三角形)
- JavaScript社区开发者调查:服务端JS盛行 AngularJS使用者最多
- Ubuntu下crontab命令的用法
- UVA 1393 - Highways
- 结构型模式之Decorator模式
- Java程序员从笨鸟到菜鸟之(四十九)细谈struts2(十一)OGNL表达式的基本语法和用法
- linux网络
- tornado模板源码小析
- 如何编写高质量和可维护的代码