The Moving Points

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

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 X
i, Y
i, VX
i and VY
i (-10
6 <= X
i, Y
i <= 10
6, -10
2 <= VX
i , VY
i <= 10
2), (X
i, Y
i) is the position of the i
th point, and (VX
i , VY
i) is its speed with direction. That is to say, after 1 second, this point will move to (X
i + VX
i , Y
i + VY
i).
 
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
 


题目大意:有n个点,这些点有各自的起始坐标和x,y方向的速度,问你在什么时刻,这些点两两之间的最大距离最小,求出时刻与距离。比赛的时候写的暴力枚举,觉得三分应该靠不住,单调性并不一定是一个抛物线的样子。最大值应该是连续的,而且是个开口向上的抛物线的单调关系。某一时刻有了最小的距离之后,会越走越远。由于求最小值,会想到三分。


题目地址:The Moving Points


三分AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
double eps=1e-6;
int n; //点的个数
struct mq
{
double x;
double y;
double vx;
double vy;
};
mq node[305]; double dis(mq a,mq b,double t)
{
return sqrt((a.x+a.vx*t-b.x-b.vx*t)*(a.x+a.vx*t-b.x-b.vx*t)+(a.y+a.vy*t-b.y-b.vy*t)*(a.y+a.vy*t-b.y-b.vy*t));
} double cal(double t)
{
int i,j;
double ans=0;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
ans=max(ans,dis(node[i],node[j],t));
return ans;
} int main()
{
int tes,i;
scanf("%d",&tes);
int cas=0;
while(tes--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&node[i].x,&node[i].y,&node[i].vx,&node[i].vy); double left,right,mid,mimid;
left=0,right=10000000;
while(right-left>eps)
{
mid=(left+right)/2.0,mimid=(right+mid)/2.0;
if(cal(mid)<cal(mimid))
right=mimid;
else
left=mid;
} printf("Case #%d: %.2f %.2f\n",++cas,mid,cal(mid));
} return 0;
} /*
45
2
0 0 1 0
2 0 -1 0
2
-1000000 0 1 0
1000000 0 -1 0
2
1000000 0 0 0
-1000000 0 0 0
2
1000000 1000000 0 0
-1000000 -1000000 0 0
3
2 2 0 0
1 1 0 0
4 4 0 0
*/

当时比赛时写的是暴力枚举的方法,也可以过的,不过精度没有卡到位,每次分成10份找最小的,慢慢等分,跟三分的思想差不多。
暴力AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
double eps=1e-6;
int n;
struct mq
{
double x;
double y;
double vx;
double vy;
};
mq node[305];
double ps,pt; void cal()
{
double fent=10000000;
double l=0,r=fent,t;
int i,j;
while(fent>eps)
{
for(t=l; t<=r; t+=fent)
{
double tmp=0;
for(i=0; i<n; i++)
for(j=i+1; j<n; j++)
{
double a,b,c,d;
a=node[i].x+node[i].vx*t;
b=node[i].y+node[i].vy*t;
c=node[j].x+node[j].vx*t;
d=node[j].y+node[j].vy*t;
double sq=sqrt((a-c)*(a-c)+(b-d)*(b-d));
if(sq>tmp)
tmp=sq;
}
if(tmp<ps)
{
ps=tmp;
pt=t;
}
}
if(pt<fent)
{
l=0,r=fent;
}
else
{
l=pt-fent,r=pt+fent;
}
fent=fent/10.0;
}
}
int main()
{
int tes,i;
scanf("%d",&tes);
int cas=0;
while(tes--)
{
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%lf%lf%lf%lf",&node[i].x,&node[i].y,&node[i].vx,&node[i].vy); ps=100000000.0;
cal();
printf("Case #%d: %.2f %.2f\n",++cas,pt,ps);
}
return 0;
} /*
45
2
0 0 1 0
2 0 -1 0
2
-1000000 0 1 0
1000000 0 -1 0
2
1000000 0 0 0
-1000000 0 0 0
2
1000000 1000000 0 0
-1000000 -1000000 0 0
3
2 2 0 0
1 1 0 0
4 4 0 0
*/


HDU 4717The Moving Points warmup2 1002题(三分)的更多相关文章

  1. hdu 4717 The Moving Points(第一个三分题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...

  2. HDU 4717 The Moving Points (三分)

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

  3. HDUOJ---The Moving Points

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

  4. HDOJ 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. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  7. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. The Moving Points hdu4717

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

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

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

随机推荐

  1. syslog实例详解rsyslog

    http://blog.csdn.net/chenhao112358/article/details/40892239http://www.cnblogs.com/blueswu/p/3564763. ...

  2. cocos2d源码剖析

    1. TextureAtlas http://www.cocoachina.com/bbs/read.php?tid-311439-keyword-TextureAtlas.html 2. Label ...

  3. HTML设置固定页脚飘浮

    Css /* 页脚 */.footSty{bottom: 0pt; margin: 0pt; position: fixed; width: 100%; z-index: 10 ! important ...

  4. Java-Android 之输入提示框

    Android的文本提示框有两种方式: main.xml文件 <?xml version="1.0" encoding="utf-8"?> < ...

  5. java web(jsp)-The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

    在静态项目上新建 jsp文件的时候,报错:The superclass "javax.servlet.http.HttpServlet" was not found on the ...

  6. Simple screenshot that explains the singleton invocation.

    Here is the code: /* Some class,such as a config file,need to be only one.So we need to control the ...

  7. 用PHP实现一个高效安全的ftp服务器(一)

    摘要: 本文主要阐述使用PHP的swoole扩展实现ftp服务器,同时扩展ftp服务器个性化功能和安全性.真正实现一个自己完全掌控的ftp服务器,可以个性化定制的ftp服务器. 正文: FTP服务器想 ...

  8. 进程识别号(PID)的理解

    PID(Process Identification)操作系统里指进程识别号,也就是进程标识符.操作系统里每打开一个程序都会创建一个进程ID,即PID. PID(进程控制符)英文全称为Process ...

  9. 【转】iOS使用NSMutableAttributedString实现富文本

    iOS使用NSMutableAttributedString实现富文本 在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘 ...

  10. FMDB多线程读写问题,使用FMDataBaseQueue操作可以解决同时打开一个链接de读写问题

    现在ios里使用的数据库一般都是Sqlite,但是使用Sqlite有个不太好的地方就是在多线程的时候,会出现问题,sqlite只能打开一个读或者写连结.这样的话多线程就会碰到资源占用的问题. 最开始是 ...