HDU 4717 The Moving Points
来源:互联网 发布:淘宝网秋冬半身裙 编辑:程序博客网 时间:2024/06/18 04:04
题意:给定n个点,然后这些点朝着给定的方向走,,在某个时间后,点停下来,可以求得此时任意两点之间的最大距离。问何时停止可以使得任意两点之间的最大距离最小。
思路:三分时间,判断条件是求出时间的情况下,任意两点之间的最大距离就好了。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const double eps=1e-8;const int MAX=330;int n;double x[MAX],y[MAX],vx[MAX],vy[MAX];double cal(double t){ double ret=0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) { double x1=x[i]+vx[i]*t; double y1=y[i]+vy[i]*t; double x2=x[j]+vx[j]*t; double y2=y[j]+vy[j]*t; ret=max(ret,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))); } return ret;}double solve(){ double l=0,r=1e10; while(r-l>=eps) { double mid1=(l+r)/2; double mid2=(mid1+r)/2; if(cal(mid1)>=cal(mid2)) l=mid1; else r=mid2; } return l;}int main(){ int icase,T=1; scanf("%d",&icase); while(icase--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&x[i],&y[i],&vx[i],&vy[i]); double t=solve(); printf("Case #%d: %.2lf %.2lf\n",T++,t,cal(t)); } return 0;}
阅读全文
0 0
- 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(三分)
- Nginx初了解
- vtk实现三点确定一个平面
- 栈溢出原理
- 数据结构思维 第四章 `LinkedList`
- MySQL学习笔记
- HDU 4717 The Moving Points
- angular 自定义过滤器>>截取字符串、去除字符串中的空格
- JavaWeb——Cookie,Session学习汇总
- mybatis的一些整理
- ZooKeeper_8_Java操作ZK_更新数据
- PC版通用布局页面
- 开发OpenCV+Qt+C++项目过程中遇到的问题及查找的答案
- maven添加本地jar到本地版本库
- 管理处理器的亲和性(affinity)