HDUOJ---The Moving Points
The Moving Points
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 612 Accepted Submission(s): 250
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).
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
2 2 0 0 1 0 2 0 -1 0 2 0 0 1 0 2 1 -1 0
Sample Output
Case #1: 1.00 0.00 Case #2: 1.00 1.00
Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
Recommend
zhuyuanchen520
三分思路:
单调性查找就好....对时间
代码:
1 #include<iostream>
2 #include<vector>
3 #include<cstdio>
4 #include<cstring>
5 #include<cstdlib>
6 #include<cmath>
7 #define MAX 1e9
8 #define exp 1e-6
9 using namespace std;
10 //设置结构体
11 typedef struct
12 {
13 int x,y;
14 int px,py;
15 }point;
16
17 //计算任意时间两点的距离
18 double das(point a,point b,double t )
19 {
20 return sqrt(pow(((a.x+a.px*t)-(b.x+b.px*t)),2)+pow(((a.y+a.py*t)-(b.y+b.py*t)),2));
21 }
22 //判断两个数最大值....
23 double max( double a,double b)
24 {
25 return a>b?a:b;
26 }
27 point po[305];
28 int main()
29 {
30 int n,i,j,cnt=1,t;
31 double ll,rr,ml,mr,ans1,ans2;
32 scanf("%d",&t);
33 while(t--)
34 {
35 scanf("%d",&n);
36 for( i=1 ; i<=n ; i++ )
37 {
38 scanf("%d%d%d%d",&po[i].x,&po[i].y,&po[i].px,&po[i].py);
39 //cin>>po[i].x>>po[i].y>>po[i].px>>po[i].py;
40 }
41 //没有其他的办法,除了遍历之外
42 ll=0.0,rr=MAX;
43 while(rr-ll>exp)
44 {
45 ans1=ans2=0.0;
46 //ml=(ll+rr)/2.0; //慢很多
47 //mr=(ml+rr)/2.0;
48 ml=(ll*2+rr)/3.0; // r/3.0 较快
49 mr=(ll+rr*2)/3.0; // 2*r/3.0
50 for( i=1 ; i<n ; i++ )
51 {
52 for( j=i+1 ; j<=n ;j++ )
53 {
54 ans1=max(ans1,das(po[i],po[j],ml)); //对左边
55 ans2=max(ans2,das(po[i],po[j],mr)); //对右边
56 }
57 }
58 if( ans1<ans2 )
59 rr=mr;
60 else
61 ll=ml;
62 }
63 //得到时间ll or rr 都可以
64 ans1=0.0;
65 for(i=1 ; i<n ; i++ )
66 {
67 for(j=1+i ; j<=n ;j++)
68 {
69 ans1=max(ans1,das(po[i],po[j],ll)); //对左边ll/rr
70 }
71 }
72 printf("Case #%d: %.2lf %.2lfn",cnt++,ll,ans1);
73 }
74 return 0;
75 }
- CListCtrl控件使用方法总结
- JavaScript基础考核真题——你能全做对吗?
- 拉手网面试题,不一样的难度
- Html 5 video/audio 格式转换 ogg
- ASP.NET MVC 开源项目Kigg解读(1)
- 一个setInterval的小问题
- scrollLeft等属性介绍
- ASP.NET MVC 开源项目Kigg解读(2)——Kigg.Core第一部分
- JavaScript 实现接口 (Interfaces In JavaScript)
- JavaScript 中的单例模式 (singleton in Javascript)
- asp.net MVC 权限设计
- Mediawiki 生成google sitemap
- Meidawiki 配置
- 利用JavaScript获取浏览器计算后的样式
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- String - 28. Implement strStr()
- Subsequence - 187. Repeated DNA Sequences
- Subsequence - 392. Is Subsequence
- parentheses - 241. Different Ways to Add Parentheses
- parentheses - 32. Longest Valid Parentheses
- parentheses - 22. Generate Parentheses
- palindrome - 132. Palindrome Partitioning II
- palindrome - 131. Palindrome Partitioning
- Parentheses - 20. Valid Parentheses
- Palindrome - 9. Palindrome Number
- Palindrome - 5. Longest Palindromic Substring
- Palindrome - 125. Valid Palindrome
- Sliding Window - 395. Longest Substring with At Least K Repeating Characters
- Sliding Window - 340. Longest Substring with At Most K Distinct Characters
- Sliding Window - 3. Longest Substring Without Repeating Characters