hdu 4717 The Moving Points(三分)
2024-10-21 13:03:21
http://acm.hdu.edu.cn/showproblem.php?pid=4717
大致题意:给出每一个点的坐标以及每一个点移动的速度和方向。
问在那一时刻点集中最远的距离在全部时刻的最远距离中最小。
比赛时一直以为是计算几何,和线段相交什么的有关。赛后队友说这是道三分,细致想了想确实是三分。试着画绘图发现它是一个凸性函数,存在一个最短距离。
然后三分时间就能够了。
#include <stdio.h>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
#define LL long long
#define _LL __int64
#define eps 1e-8
#define PI acos(-1.0)
using namespace std; const int maxn = 310;
const int INF = 0x3f3f3f3f; struct node
{
double x,y,vx,vy;
}p[maxn],tp[maxn];
int n;
double mindis,time;
double dis(node a, node b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
} double cal(double t)
{
for(int i = 1; i <= n; i++)
{
tp[i].x = p[i].x + t * p[i].vx;
tp[i].y = p[i].y + t * p[i].vy;
}
double Max = -1.0;
for(int i = 1; i < n; i++)
{
for(int j = i+1; j <= n; j++)
{
double ans = dis(tp[i], tp[j]);
if(Max < ans)
Max = ans;
}
}
return Max;
} void solve()
{
double low = 0, high = INF, mid,midmid; while(high - low > eps)
{
mid = (high + low)/2;
midmid = (mid + high)/2; double ans1 = cal(mid);
double ans2 = cal(midmid); if(ans1 > ans2)
low = mid;
else
high = midmid;
}
time = low;
mindis = cal(low);
} int main()
{
int test;
scanf("%d",&test);
for(int item = 1; item <= test; item++)
{
scanf("%d",&n);
for(int i = 1; i <= n; i++)
scanf("%lf %lf %lf %lf",&p[i].x, &p[i].y, &p[i].vx,&p[i].vy);
solve();
printf("Case #%d: %.2lf %.2lf\n",item,time,mindis);
}
return 0;
}
最新文章
- android——判断网络状态
- React之JSX
- Android_bug之 task &#39;:app:mergeDebugResources&#39;. >; Some file crunching failed, see logs f
- Linux内核分析——操作系统是如何工作的
- 20145207 《Java程序设计》第二周学习总结
- Linq的Distinct方法的扩展
- Python实现Apriori
- linux shell 命令学习(3) split - split a file into pieces
- Android模拟器访问本地的apache tomcat服务
- ubuntu下查看文件md5
- LNMP安装包sh脚本
- 5.中文问题(自身,操作系统级别,应用软件的本身),mysql数据库备份
- MySQL 触发器结构及三个案例demo
- C语言,如何检查文件是否存在和权限的信息
- 使用 Python 实现命令行词典(一)
- 聊聊并发-Java中的Copy-On-Write容器
- 关于C++中计时的方法
- html 页面 判断第一个反应的网站并进行跳转 模仿CDN
- ES6学习笔记八(module模块export)
- 卷积神经网络(CNN)张量(图像)的尺寸和参数计算(深度学习)
热门文章
- C语言 - 头文件使用案例
- [AHOI 2008] 聚会
- SpringAop中JoinPoint对象
- Windows Server 2012 / 2016 安装 .Net Framework 3.5(PowerShell)
- 26. Remove Duplicates from Sorted Array[E]删除排序数组中的重复项
- 基于Apache Thrift的公路涵洞数据交互实现原理
- 关于PHP中的SESSION技术
- angular中的ng-click指令案例
- BeautifulSoup 库的使用记录
- java是值传递,还是引用传递?