hdu 4717(三分求极值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717
思路:三分时间求极小值。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; const int MAX_N = (300 + 30);
const double eps = 1e-5; struct Point {
double x, y;
double vx, vy;
} point[MAX_N]; int N;
double ans; double getDist(int i, int j, double t_time)
{
double x1 = (point[i].x + t_time * point[i].vx);
double y1 = (point[i].y + t_time * point[i].vy);
double x2 = (point[j].x + t_time * point[j].vx);
double y2 = (point[j].y + t_time * point[j].vy); return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
} double check(double t_time)
{
double res = 0.0;
for (int i = 1; i <= N; ++i) {
for (int j = i + 1; j <= N; ++j) {
res = max(res, getDist(i, j, t_time));
}
}
ans = min(ans, res); return res;
} int main()
{
int Cas, t = 1;
scanf("%d", &Cas);
while (Cas--) {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%lf %lf %lf %lf", &point[i].x, &point[i].y, &point[i].vx, &point[i].vy);
} if (N == 1) {
printf("%.2f %.2f\n", 0, 0);
continue;
} ans = 1e18; double low = 0.0, high = 1e8, mid, mmid;
while (low + eps < high) {
mid = (low + high) / 2.0;
mmid = (mid + high) / 2.0;
if (check(mid) <= check(mmid)) {
high = mmid;
} else
low = mid;
} printf("Case #%d: %.2f %.2f\n", t++, low, ans);
}
return 0;
}
hdu 4717(三分求极值)的更多相关文章
- HLJU 1221: 高考签到题 (三分求极值)
1221: 高考签到题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 9 Solved: 4 [Submit][id=1221">St ...
- hihocoder 1142 三分求极值【三分算法 模板应用】
#1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一 ...
- Hihocoder #1142 : 三分·三分求极值
1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个 ...
- hihocoder 1142 三分·三分求极值(三分)
题目1 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点 ...
- ZOJ 3203 Light Bulb( 三分求极值 )
链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...
- HDU 4355 Party All the Time (三分求极值)
题意:给定x轴上有n个点,每一个点都有一个权值,让在x轴上选一个点,求出各点到这个点的距离的三次方乘以权值最小. 析:首先一开始我根本不会三分,也并没有看出来这是一个三分的题目的,学长说这是一个三分的 ...
- hdu 4717(三分) The Moving Points
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 n个点,给出初始坐标和移动的速度和移动的方向,求在哪一时刻任意两点之间的距离的最大值的最小. 对于最 ...
- hihocoder 第四十周 三分求极值
题目链接:http://hihocoder.com/contest/hiho40/problem/1 ,一道简单的三分. 题目是在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求 ...
- hicoder1142 三分求极值
在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. 我们代入公式,有: $d = min(\sqrt{(X - x)^2+(aX^2+bX+c-y)^2 ...
随机推荐
- npm命令教程
教程:http://www.runoob.com/nodejs/nodejs-npm.html 常用命令:http://www.cnblogs.com/PeunZhang/p/5553574.html
- Codeforces Round #342 (Div. 2) A. Guest From the Past(贪心)
传送门 Description Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the detai ...
- python异常处理
1. 异常 (1) 异常处理 #没有异常处理 num = int('abc') print(num) #报错 #异常处理 try: num = int('abc') #try里的代码是受保护的 pri ...
- elasticsearch agg
OK curl -XGET http://21.3.5.121:9200/ipv4geo/service/_count -d '{"query":{"match" ...
- .NET简谈事务、分布式事务处理
http://www.cnblogs.com/wangiqngpei557/archive/2011/12/22/2298500.html
- 纯js+css实现loading等待效果
此插件是基于jqueryUI的widget,下面是具体实现代码 第一部分css: /***loading***/ .loading-box{ position:absolute; text-align ...
- js高级群的一些整理6月
https://github.com/the5fire/backbonejs-learning-note/blob/master/chapters/01-hello-backbonejs.rst Ba ...
- vertx verticle
以下内容为随手记的,若看客不知鄙人所云,还请原谅则个.............. 公司用的vertx,在国内,这还是款比较年轻的框架,你也可以把他当做一个工具,官网上的说法是: Vert.x is a ...
- Hadoop 2.6.0+ZooKeeper+Hive HA高可用集群安装
http://blog.csdn.net/totxian/article/details/45248399
- C#学习链接
.NET Framework — 针对 .NET 构建企业级搜索:https://msdn.microsoft.com/zh-cn/magazine/dn904674.aspx .net 动态编译:h ...