hdu 4717: The Moving Points 【三分】
第一次写三分
三分的基本模板
int SanFen(int l,int r) //找凸点
{
while(r-l>)
{
//mid为中点,midmid为四等分点
int mid = (l+r)/;
int midmid = (mid+r)/;
if( f(mid) > f(midmid) )
r = midmid;
else
l = mid;
}
return f(l) > f(r) ? l : r;
}
这道题里面任意两点的距离都可以看作是一个凹函数,对任意t对所有凹函数取最大值构成一个新的凹函数,求新函数的最小值
#include<bits/stdc++.h>
using namespace std;
typedef long long LL; const int N=;
const double eps=1e-; int T,n;
double tim,mindis; struct point
{
double x,y;
int dx,dy;
}p[N]; double dist(point p1,point p2,double t)
{
double x2=(p1.x+t*p1.dx-p2.x-t*p2.dx)*(p1.x+t*p1.dx-p2.x-t*p2.dx);
double y2=(p1.y+t*p1.dy-p2.y-t*p2.dy)*(p1.y+t*p1.dy-p2.y-t*p2.dy);
return sqrt(x2+y2);
} double cal(double x)
{
double ret=-;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
ret=max(ret,dist(p[i],p[j],x));
return ret;
} void solve()
{
double l=,r=1e8;
while(r-l>eps)
{
double mid=(l+r)/;
double midmid=(mid+r)/;
double ans1=cal(mid);
double ans2=cal(midmid);
if(ans1>ans2) l=mid;
else r=midmid;
}
tim=l;
mindis=cal(tim);
} int main()
{
scanf("%d",&T);
for(int kase=;kase<=T;kase++)
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lf%lf%d%d",&p[i].x,&p[i].y,&p[i].dx,&p[i].dy);
solve();
printf("Case #%d: %.2lf %.2lf\n",kase,tim,mindis);
}
}
hdu 4717: The Moving Points 【三分】的更多相关文章
- HDU 4717 The Moving Points(三分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...
- HDU 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(第一个三分题)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...
- hdu 4717 The Moving Points(三分+计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...
- hdu 4717 The Moving Points(三分)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 大致题意:给出每一个点的坐标以及每一个点移动的速度和方向. 问在那一时刻点集中最远的距离在全部时刻的最远距 ...
- HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description There are N points in total. Every point moves in certain direction and certain speed. W ...
- HDU 4717 The Moving Points (三分法)
题意:给n个点的坐标的移动方向及速度,问在之后的时间的所有点的最大距离的最小值是多少. 思路:三分.两点距离是下凹函数,它们的max也是下凹函数.可以三分. #include<iostream& ...
- HDOJ 4717 The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu4717The Moving Points(三分)
链接 需要特判一下n=1的时候 精度调太低会超时 #include <iostream> #include<cstdio> #include<cstring> #i ...
随机推荐
- linux gsensor驱动分析【转】
本文转载自:http://blog.sina.com.cn/s/blog_89f592f501013sr2.html 本文以Bma250驱动为例子,详细介绍Gsensor设计的一个模板. gsenso ...
- isinstance(object, classinfo) class type(name, bases, dict)
w https://docs.python.org/3/library/functions.html#isinstance
- day51—JavaScript绑定事件
转换学开发,代码100天——2018-05-06 今天学习JavaScript的绑定事件.因为浏览器的原因绑定事件需要考虑兼容性问题. attachEvent IE浏览器 ,ie9以上事件执行 ...
- QTP技术支持之QTP对象无法识别(转自582357212的个人空间,链接:http://www.51testing.com/html/64/305564-847787.html)
QTP自动化测试从业者,或者很多练习使用QTP开发自动化测试代码的人员遇到最多的问题恐怕就是对象无法识别了,对象无法识别原因有很多种,根据经常对QTP自动化测试脚本开发人员的技术Support,我总结 ...
- Android Framework中Thread类
Thread类是Android为线程操作而做的一个封装.代码在Thread.cpp中,其中还封装了一些与线程同步相关的类. Thread类 Thread类的构造函数中的有一个canCallJava T ...
- 如何快速查找到多个字典中的公共键(Key)---Python数据结构与算法相关问题与解决技巧
如何快速查找到多个字典中的公共键(Key)-? 实际案例: 西班牙足球甲级联赛,每轮球员进球统计: 第1轮: { '苏亚雷斯':1,'梅西':2,'本泽马':1,...} 第2轮: { '苏亚雷斯 ...
- Python笔记(二十八)_魔法方法_迭代器
迭代器用于遍历容器中的数据,但它不是容器,它是一个实现了__next__方法的对象 与迭代器相关的内置函数: iter(): 将一个对象转换成一个迭代器 next(): 访问迭代器中的下一个变量,直到 ...
- ELK 学习
[Udemy] ES 7 and Elastic Stack - part 1 [Udemy] ES 7 and Elastic Stack - part 2 [Udemy] ES 7 and Ela ...
- mysql 函数 时间函数,数学函数,字符串函数,条件判断函数
=========================================== mysql 相关函数 ============================================= ...
- PTA第四周作业
一.本周完成的作业 7-2 选择法排序 (20 分) 本题要求将给定的n个整数从大到小排序后输出. 输入格式: 输入第一行给出一个不超过10的正整数n.第二行给出n个整数,其间以空格分隔. 输出格式: ...