hdu4717(三分法)
来源:互联网 发布:主播用的唱歌软件 编辑:程序博客网 时间:2024/05/17 22:19
The Moving Points
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 937 Accepted Submission(s): 380
Problem Description
There are N points in total. Every point moves in certain direction and certain speed. We want to know at what time that the largest distance between any two points would be minimum. And also, we require you to calculate that minimum distance. We guarantee that no two points will move in exactly same speed and direction.
Input
The 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 Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
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 Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
Output
For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.
Sample Input
220 0 1 02 0 -1 020 0 1 02 1 -1 0
Sample Output
Case #1: 1.00 0.00Case #2: 1.00 1.00
Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you: 4812 4811 4810 4809 4808
本题给定一些点,然后个顶点的速度,求所有点对的最大距离最小的时刻和这个最小距离。
题目暗示这样的时刻唯一,所以可以这只三分求极值。时间复杂度O(N^2*log3(N)),可以接受。
#include<iostream>#include<cmath>using namespace std;const int MAXN=300+100;const double eps=1e-8;int n;double Time;struct point{double x,y;double s_x,s_y;}MyPoint[MAXN];double GetMinDistence(double tim){double tMinD=0;for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){double tix=MyPoint[i].x+MyPoint[i].s_x*tim;double tiy=MyPoint[i].y+MyPoint[i].s_y*tim;double tjx=MyPoint[j].x+MyPoint[j].s_x*tim;double tjy=MyPoint[j].y+MyPoint[j].s_y*tim;double tmp=sqrt((tix-tjx)*(tix-tjx)+(tiy-tjy)*(tiy-tjy));if(tmp>tMinD)tMinD=tmp;}}return tMinD;}void Solve(){double low,high,mid,midmid;low=0.0,high=1e10;while(high-low>=eps){mid=(low+high)/2.0;midmid=(mid+high)/2.0;if(GetMinDistence(midmid)<GetMinDistence(mid))low=mid;else high=midmid;}Time=(high+low)/2;}int main(){int cas,tag=0;cin>>cas;while(cas--){scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lf%lf%lf%lf",&MyPoint[i].x,&MyPoint[i].y,&MyPoint[i].s_x,&MyPoint[i].s_y);Solve();printf("Case #%d: %0.2lf %0.2lf\n",++tag,Time,GetMinDistence(Time));}system("pause");return 0;}
- hdu4717(三分法)
- HDU4717 :The Moving Points(三分法)
- HDU4717
- HDU4717
- HDU4717
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 三分法
- 整理的微软面试题
- STATA日期型数据处理
- c语言学习3
- 关于三线程防杀的一些思想和VC代码
- 百度+Google=天下无敌
- hdu4717(三分法)
- 全排列算法 -- 字典序法(去重)
- android 代码设置字体大小
- 理解 pkg-config 工具
- Selenium-AndroidDriver(python) (八) --- 无法输入中文
- Linux下RPM软件包的安装及卸载
- 【算法导论】图的广度优先搜索遍历(BFS)
- C# Thread类
- 标题栏设置