hdu4717-(The Moving Points)
来源:互联网 发布:诛仙手游道法对应数据 编辑:程序博客网 时间:2024/06/09 21:05
训练赛这道题没做出来,因为一开始看错题意了,后来一直wa到怕,直接pass。
题目大意:给出N个点,每个点都在向某个方向移动,且题目保证没有两个点具有相同的速度和移动方向。求在什么时候任意两点之间的最大距离最短(这里当时没看懂)。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717。
大体思路:这里可能需要脑补一下,所求任意两点最大距离最短的值关于时间 t 是一个类似于二次函数的函数或单调函数,在纸上画一下就可以知道,至于严格证明,单调函数主要考虑两个点再一开始就已经是距离最短的情况(比如两个相离的点移动的情况),而类似于二次函数的就是比较普通的,比如两个相向的点或移动路线有交叉的点。这里只举例有两个点的情况,当有N(N>2)个点时,其实也是一样的。所以既然涉及二次函数,那么就可以用三分法来做,答案保留小数点后两位,以时间来三分,左界限肯定是0,右界限考虑X,Y的取值范围,设置为1e7就够了,那么精度设置为1e-4就够了。
一下是ac代码:
#include<iostream>#include<stdio.h>#include<stack>#include<queue>#include<deque>#include<algorithm>#include<string>#include<string.h>#include<math.h>#include<set>#include<vector>using namespace std;int n;const int maxn=305;struct Point{ double x,y,vx,vy;};Point p[maxn];double calc(double x){ double ans=0; for(int i=1;i<n;i++){ for(int j=i+1;j<=n;j++){ double x1=p[i].x+x*p[i].vx; double y1=p[i].y+x*p[i].vy; double x2=p[j].x+x*p[j].vx; double y2=p[j].y+x*p[j].vy; ans=max(ans,sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2))); } } return ans;}int main(){int t;scanf("%d",&t); for(int i=1;i<=t;i++){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy); double l=0,r=1e7; while((r-l)>=1e-4){ double mid1=(2*l+r)/3; double mid2=(l+2*r)/3; double tmp1=calc(mid1); double tmp2=calc(mid2); if(tmp1<tmp2) r=mid2; else l=mid1; } printf("Case #%d: ",i); printf("%.2lf %.2lf\n",l,calc(l)); }return 0;}
0 0
- hdu4717 The Moving Points
- HDU4717-The Moving Points
- hdu4717-(The Moving Points)
- 【hdu4717】The Moving Points
- HDU4717 :The Moving Points(三分法)
- hdu4717 The Moving Points 三分
- hdu4717 The Moving Points(二分做法)
- HDU4717 The Moving Points(三分)
- hdu4717 The Moving Points 三分求函数最小值
- hdu_4717 The Moving Points
- B - 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
- mybits配置条件
- 二. Scala编程之简介
- bootstrap日期时间选择器datepicker的使用
- 学生信息的添加与查询 oj
- Linux开发二十三_opencv移植
- hdu4717-(The Moving Points)
- 计算机基础之牛客网刷题第五篇
- 逻辑运算符
- 安装PyCrypto库及其使用(Python3安装)
- Linux开发二十四_mplayer移植
- Bilibili爬虫之爬取小黑屋
- Eclipse+Tomcat+maven+springMVC环境搭建出错总结
- C++对象模型-详述C++对象的内存布局
- Hadoop2.x搭建步骤