HDU 4717 The Moving Points
来源:互联网 发布:lolypop女装淘宝网 编辑:程序博客网 时间:2024/06/03 16:41
题意:给定n个点,每个点有自己的移动速度和方向,求出某一个时间内的最大距离的最小值~~~~
题目链接: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
- 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
- HDU 4717 The Moving Points
- HDU 4717 The Moving Points
- The Moving Points HDU
- 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(三分)
- JS获取字符串长度 (一个汉字长度视为1)
- poj3308Paratroopers(最小割)
- WCF开发错误处理记录(无法激活服务,因为它不支持 ASP.NET 兼容性)
- Android项目(三)-- Activity生命周期演示
- 两个月的编程教会我很多
- HDU 4717 The Moving Points
- 钽电容规格定义
- 备忘
- ASLR/DEP绕过技术概览
- 对象的作用域
- HDU 4722 Good Numbers
- 如何开启MySQL慢查询日志
- JS获取字符串长度(一个汉字视为2个单位长度)
- nvalid command 'PythonPath', perhaps misspelled or defined by a module not included in the server co