The Moving Points

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 612    Accepted Submission(s): 250

Problem Description
There are N points in total. Every point moves in certain direction and certain speed. We want to know at what time that the largest distance between any two points would be minimum. And also, we require you to calculate that minimum distance. We guarantee that no two points will move in exactly same speed and direction.
 
Input
The rst line has a number T (T <= 10) , indicating the number of test cases. For each test case, first line has a single number N (N <= 300), which is the number of points. For next N lines, each come with four integers Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
 
Output
For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.
 
Sample Input
2 2 0 0 1 0 2 0 -1 0 2 0 0 1 0 2 1 -1 0
 
Sample Output
Case #1: 1.00 0.00 Case #2: 1.00 1.00
 
Source
 
Recommend
zhuyuanchen520
三分思路:
单调性查找就好....对时间
代码:
 #include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#define MAX 1e9
#define exp 1e-6
using namespace std;
//设置结构体
typedef struct
{
int x,y;
int px,py;
}point; //计算任意时间两点的距离
double das(point a,point b,double t )
{
return sqrt(pow(((a.x+a.px*t)-(b.x+b.px*t)),)+pow(((a.y+a.py*t)-(b.y+b.py*t)),));
}
//判断两个数最大值....
double max( double a,double b)
{
return a>b?a:b;
}
point po[];
int main()
{
int n,i,j,cnt=,t;
double ll,rr,ml,mr,ans1,ans2;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for( i= ; i<=n ; i++ )
{
scanf("%d%d%d%d",&po[i].x,&po[i].y,&po[i].px,&po[i].py);
//cin>>po[i].x>>po[i].y>>po[i].px>>po[i].py;
}
//没有其他的办法,除了遍历之外
ll=0.0,rr=MAX;
while(rr-ll>exp)
{
ans1=ans2=0.0;
//ml=(ll+rr)/2.0; //慢很多
//mr=(ml+rr)/2.0;
ml=(ll*+rr)/3.0; // r/3.0 较快
mr=(ll+rr*)/3.0; // 2*r/3.0
for( i= ; i<n ; i++ )
{
for( j=i+ ; j<=n ;j++ )
{
ans1=max(ans1,das(po[i],po[j],ml)); //对左边
ans2=max(ans2,das(po[i],po[j],mr)); //对右边
}
}
if( ans1<ans2 )
rr=mr;
else
ll=ml;
}
//得到时间ll or rr 都可以
ans1=0.0;
for(i= ; i<n ; i++ )
{
for(j=+i ; j<=n ;j++)
{
ans1=max(ans1,das(po[i],po[j],ll)); //对左边ll/rr
}
}
printf("Case #%d: %.2lf %.2lf\n",cnt++,ll,ans1);
}
return ;
}

HDUOJ---The Moving Points的更多相关文章

  1. HDOJ 4717 The Moving Points

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. HDU 4717The Moving Points warmup2 1002题(三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. The Moving Points hdu4717

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. HDU 4717 The Moving Points (三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. HDU-4717 The Moving Points(凸函数求极值)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. F. Moving Points 解析(思維、離散化、BIT、前綴和)

    Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...

  7. The Moving Points

    Problem Description There are N points in total. Every point moves in certain direction and certain ...

  8. The Moving Points HDU - 4717

    There are N points in total. Every point moves in certain direction and certain speed. We want to kn ...

  9. HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description There are N points in total. Every point moves in certain direction and certain speed. W ...

随机推荐

  1. bit byte哪些事

    1.bit 电脑中最小的计量单位,比如0或1代表一个bit,简称“位” 2.byte 电脑存储的基本单位.因为上面的bit小弟太小了,所以产生了byte.由8个bit存成了byte,最小为0最大为11 ...

  2. 解决hue/hiveserver2对于hive date类型显示为NULL的问题

    用户报在Hue中执行一条sql:select admission_date, discharge_date,birth_date from hm_004_20170309141149.inpatien ...

  3. chromium对网页获取favicon

    每一个网页都有一个favicon,在历史记录的保存中须要用到.在content文件夹下,这个没有实现. 以下说一下我的实现过程: web_contents_impl.cc文件里有方法:WebConte ...

  4. C++运算符重载(友元函数方式)

    我们知道,C++中的运算符重载有两种形式:①重载为类的成员函数(见C++运算符重载(成员函数方式)),②重载为类的友元函数. 当重载友元函数时,将没有隐含的参数this指针.这样,对双目运算符,友元函 ...

  5. scala编程第19章学习笔记(1)——类型参数化

    一.queues函数式队列 函数式队列是一种具有以下三种操作方式的数据结构: head 返回队列的第一个元素. tail 返回除第一个元素之外的队列. scala> import scala.c ...

  6. C++中new的用法及显示调用析构函数

    最近被问到了C++内存池的问题,其中不免涉及到在指定内存地址调用对象构造函数以及显示调用对象析构函数的情况. C++中new的用法 new是C++中用于动态内存分配的运算符,在C语言中一般使用mall ...

  7. linux下永久添加静态路由

    在linux下永久添加静态路由有两种方法: 添加路由的命令: 1,route add route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0 ...

  8. jquery选择器用法笔记(第二部分)

    今天继续讲讲jquery选择器的更多用法,希望能给大家带来帮助. 9.$("ul li:eq(3)")  --  列表中的第四个元素(index 从 0 开始) :eq() 选择器 ...

  9. 【nodejs】理想论坛帖子下载爬虫1.06

    //====================================================== // 理想论坛帖子下载爬虫1.06 // 循环改成了递归,但最多下载千余文件就崩了 / ...

  10. 将浮点数保持几位小数,尾数舍入的Format函数

    select format(hours,2) from pos.daywork