The Moving Points HDU - 4717
InputThe 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 thpoint, 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).OutputFor 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 这题也是三分的入门题(水题)
给你N个坐标,和每秒在特定方向的移动速度。
求出最大距离的最小值。(是不是和我上一篇写的,题目非常的相似)
其实两点之间的距离与时间t的关系刚好是一个二次函数。
其实又是构造一个由最大值组成的二次函数求出这个新的二次函数的最小值
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
struct node
{
double x,y,vx,vy;
}a[];
double f(node a,node 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 check(double x)
{
double maxn=;
for (int i= ;i<n ;i++){
for (int j=i+ ;j<n ;j++){
maxn=max(maxn,f(a[i],a[j],x));
}
}
return maxn;
}
int main() {
int t,cas=;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for (int i= ;i<n ;i++){
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].vx,&a[i].vy);
}
double l=,r=;
while(r-l>1e-){
double lmid=l+(r-l)/;
double rmid=r-(r-l)/;
if (check(lmid)>check(rmid)) l=lmid;
else r=rmid;
}
printf("Case #%d: %.2lf %.2lf\n",cas++,l,check(l));
}
return ;
}
The Moving Points HDU - 4717的更多相关文章
- The Moving Points - HDU - 4717 (模拟退火)
题意 二维空间中有\(n\)个运动的点,每个点有一个初始坐标和速度向量.求出一个时间\(T\),使得此时任意两点之间的最大距离最小.输出\(T\)和最大距离. 题解 模拟退火. 这个题告诉了我,初始步 ...
- HDU 4717 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 4717The Moving Points warmup2 1002题(三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- The Moving Points hdu4717
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 ...
- HDU-4717 The Moving Points(凸函数求极值)
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的題目更容易 ...
- HDU 4717 The Moving Points(三分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...
随机推荐
- 洛谷 [P3355] 骑士共存问题
二分图求最大独立点集 本问题在二分图中已处理过,此处用dinic写了一遍 #include <iostream> #include <cstdio> #include < ...
- 浅析Numpy.genfromtxt及File I/O讲解
Python 并没有提供数组功能,虽然列表 (list) 可以完成基本的数组功能,但它并不是真正的数组,而且在数据量较大时,使用列表的速度就会慢的让人难受.为此,Numpy 提供了真正的数组功能,以及 ...
- Docker Compose容器编排
Compose是Docker官方的开源项目,可以实现对Docker容器集群的快速编排.Compose 中有两个重要的概念:服务(service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实 ...
- 使用ssh 登录Linux 文件上传下载方法
最简单的方法: 安装WinSCP或者Filezilla, 启动该程序,然后自己输入输入主机名.端口.用户名.密码登录,然后在putty里面用pwd命令看看当前目录,再在WinSCP/Filezilla ...
- CentOS 7 安装Java 1.8
携程的Apollo配置中心服务端[https://github.com/ctripcorp/apollo/wiki]推荐的Java版本是:1.8+, 本文介绍如何在CentOS上安装java 1.8. ...
- Docker MySQL备份
建立备份的MySQL容器 docker run --name mysql-back -e MYSQL_ROOT_PASSWORD=root -v /srv/mysql/backup:/mysql/ba ...
- nodejs和npm的安装
下载nodejs的压缩包 网址:https://nodejs.org/en/ 下载以tar.xz结尾的包例如:node-v8.9.4-linux-x64.tar.xz 上传包到制定的目录 可以用lrz ...
- [记录]Python2.7使用argparse模块
# -*- coding: utf8 -*- import argparse #ArgumentParser.add_argument(name or flags-[, action][, nargs ...
- echarts legend 重叠 (转载)
解决方案: 1. 调整option中的grid.top值才能避免重叠:(可以设置定制,也可以定义了一个计算公式) 2. 文档注明[特殊字符串 ''(空字符串)或者 '\n' (换行字符串)用于图例的 ...
- linux 命令:tr 的简单使用
工作的需要,用到了tr命令,因为用到的次数不是很多,怕以后忘记了百度,就自己总结下.例子什么的,copy linux shell 脚本攻略这本书. tr:常用选项 -c 用字符串1中字符集的补集替换此 ...