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 ...
随机推荐
- JQuery 实现标题与内容相呼应样式
效果图如下:鼠标移到标题上,标题下面显示标题对应的内容.实现的方法如下: 1.引入css和js文件 <link href="public/CSS/StyleSheet.css" ...
- 问你觉得iOS7为什么要扁平化,扁平化和之前的比有什么优势
问你觉得iOS7为什么要扁平化,扁平化和之前的比有什么优势 苹果首席设计师谈为何会在iOS上选择扁平风格http://ndnews.oeeee.com/html/201306/11/71078.htm ...
- jQuery实现的表格展开伸缩效果实例
<table> <thead> <tr> <th>姓名</th> <th>性别</th> <th>暂住地 ...
- insert into output使用
declare @t table (logId int,customerId int,amount int) insert into log( customerId,amount) output in ...
- javascript数据结构与算法---栈
javascript数据结构与算法---栈 在上一遍博客介绍了下列表,列表是最简单的一种结构,但是如果要处理一些比较复杂的结构,列表显得太简陋了,所以我们需要某种和列表类似但是更复杂的数据结构---栈 ...
- tyvj4541 zhx 提高组P1
背景 提高组 描述 在一个N×M的棋盘上,要求放置K个车,使得不存在一个车同时能被两个车攻击.问方案数. 输入格式 一行三个整数,N,M,K. 输出格式 一行一个整数,代表答案对1000001取模之后 ...
- css中为了清除浮动经常用到的after样式
.cf:after { display: block; visibility: hidden; width:; height:; line-height:; font-size:; clear: bo ...
- I18N 国际化
http://blog.sina.com.cn/s/blog_6c7e59770101p7w9.html 一.I18N 在 J2EE 中的应用 [转载:http://blog.csdn.net/cha ...
- Qml 写的弹出层控件
QML弹出窗口组件,灯箱效果.动画效果,可拖拽 核心思路:一个mask层,一个最顶层,都用rectangle,禁止事件穿透 使用 Popup { id: popup width: 200; heigh ...
- discuz上传图片提示附件文件无法保存
两个可能: 1. 服务器文件夹权限不足 discuz附件保存在./data/attachments下,data文件夹的属性要求必须为777 #cd到data的上一级目录然后执行: data 2. 附件 ...