HDU 4717The Moving Points warmup2 1002题(三分)
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
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).
2
0 0 1 0
2 0 -1 0
2
0 0 1 0
2 1 -1 0
Case #2: 1.00 1.00
题目大意:有n个点,这些点有各自的起始坐标和x,y方向的速度,问你在什么时刻,这些点两两之间的最大距离最小,求出时刻与距离。比赛的时候写的暴力枚举,觉得三分应该靠不住,单调性并不一定是一个抛物线的样子。最大值应该是连续的,而且是个开口向上的抛物线的单调关系。某一时刻有了最小的距离之后,会越走越远。由于求最小值,会想到三分。
题目地址:The Moving Points
#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
*/
#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题(三分)的更多相关文章
- hdu 4717 The Moving Points(第一个三分题)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...
- HDU 4717 The Moving Points (三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDUOJ---The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDOJ 4717 The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU-4717 The Moving Points(凸函数求极值)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 2802 F(N)(简单题,找循环解)
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- The Moving Points hdu4717
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- F. Moving Points 解析(思維、離散化、BIT、前綴和)
Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...
随机推荐
- CentOS iSCSI客户端使用配置
配置步骤: 1.查看安装是否安装iSCSI驱动 rpm -qa|grep iscsi 2.查看yum安装源 yum list |grep iscsi 3.安装iscsi驱动 yum install i ...
- 【nodejs】创建udp套接字的类型参数的含义
nodejs在创建udp套接字的时候,需要传入一个类型参数.有两种类型参数可供选择:udp4和udp6.udp4对应的就是ipv4,udp6对应的是ipv6.
- [转] npm 模块安装机制简介
npm 是 Node 的模块管理器,功能极其强大.它是 Node 获得成功的重要原因之一. 正因为有了npm,我们只要一行命令,就能安装别人写好的模块 . $ npm install 本文介绍 npm ...
- iOS中__block 关键字的底层实现原理
在 <iOS面试题集锦(附答案)> 中有这样一道题目: 在block内如何修改block外部变量?(38题)答案如下: 默认情况下,在block中访问的外部变量是复制过去的,即:写操作不对 ...
- 汉诺塔-Hanoi
1. 问题来源: 汉诺塔(河内塔)问题是印度的一个古老的传说. 法国数学家爱德华·卢卡斯曾编写过一个印度的古老传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度教的主神梵 ...
- Java——(七)Map之HashMap和Hashtable实现类
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- Map Map用于具有映射关系的数据,因此Map集合里保存着两组值,一组值用于保存Map里的ke ...
- linux意外关机,如何修复
意外关机后,提示an error occurred during the file system check. 解决方法,输入root密码 执行 fdisk -l 查看磁盘 (Repair files ...
- thread跟Runnable实现多线程
//两种实现方式的区别和联系: //在程序开发中只要是多线程肯定永远以实现Runnable接口为主,因为实现Runnable接口相比继承Thread类有如下好处: //避免点继承的局限,一个类可以继承 ...
- sql根据'/'截取最后的字符串
filpath字段值:/DataFile/UpLoad/Logo/NoPhoto.jpg select filpath,REVERSE((SUBSTRING(REVERSE(FilPath),0,CH ...
- Wpf 鼠标拖动元素实例
1.Wpf中鼠标捕获和释放 //以矩形为例 //创建鼠标捕获 Mouse.Capture(rectOne); //释放鼠标捕获 rectOne.ReleaseMouseCapture(); 2.Wpf ...