HDU 4717 The Moving Points
2013-09-12 17:18
363 查看
题意:给定n个点,每个点有自己的移动速度和方向,求出某一个时间内的最大距离的最小值~~~~
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717
思路:
刚开始以为时间是整数,所以没理解为什么在最后的输出时浮点数的格式,
果断改掉,时间不一定是整数,从而三分解决~~~
第一次使用三分,果断不熟,还好,,过掉
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717
思路:
刚开始以为时间是整数,所以没理解为什么在最后的输出时浮点数的格式,
果断改掉,时间不一定是整数,从而三分解决~~~
第一次使用三分,果断不熟,还好,,过掉
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int Max=310; struct Point{ double x,y; double vx,vy; }; Point p[Max],a[Max]; int n; double Distance(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double F(double mid){ for(int j=0;j<n;j++){ p[j].x=a[j].x+p[j].vx*mid; p[j].y=a[j].y+p[j].vy*mid; } double ans = -100000000,temp; for(int k=0;k<n;k++){ for(int h=k+1;h<n;h++){ temp=Distance(p[k],p[h]); if(ans < temp) ans = temp; } } return ans; } int main() { int T; scanf("%d",&T); for(int ncase = 1; ncase <= T; ncase++){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lf %lf %lf %lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy); a[i].x=p[i].x;a[i].y=p[i].y,a[i].vx=p[i].vx,a[i].vy=p[i].vy; } double L = 0.0,R = 1000.0; for(int i=0;i<100;i++){ double m1=L+(R-L)/3; double m2=R-(R-L)/3; if(F(m1)<F(m2)) R=m2; else L = m1; } printf("Case #%d: %.2lf %.2lf\n",ncase,L,F(L)); } }
相关文章推荐
- HDU 4717 The Moving Points
- HDU 4717 The Moving Points (三分 模板)
- The Moving Points HDU - 4717 (三分查找)
- HDU - 4717 The Moving Points —— 三分
- HDU 4717 The Moving Points(三分)
- The Moving Points -HDU 4717 三分
- HDU 4717 The Moving Points
- HDU 4717 The Moving Points (三分 模板)
- hdu 4717 The Moving Points(三分)
- HDU - 4717 The Moving Points —— 三分
- HDU 4717 The Moving Points(三分枚举)
- HDU 4717 The Moving Points (三分 模板)
- The Moving Points HDU - 4717 (三分)
- HDU 4717 The Moving Points (三分 模板)
- HDU 4717 The Moving Points
- hdu 4717 The Moving Points(第一个三分题)
- HDU 4717 The Moving Points
- HDU 4717 The Moving Points (三分 模板)
- HDU 4717 The Moving Points (三分 模板)
- HDU 4717 The Moving Points (三分搜索)