文章标题
来源:互联网 发布:重复犯错歌词意思 知乎 编辑:程序博客网 时间:2024/06/07 06:21
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 X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).
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
题意:在一个平面上有很多运动的点,问那一个时刻,所有点的最大距离最小。
先减后增 因为绝对不会先增后减 就是下凸模型
三分法
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;int n;const double les=1e-6;struct node{ double x,y,vx,vy;}a[500];double dis(node a,node b,double t){ return sqrt((a.x+a.vx*t-b.x-b.vx*t)*(a.x+a.vx*t-b.x-b.vx*t) +(a.y+a.vy*t-b.y-b.vy*t)*(a.y+a.vy*t-b.y-b.vy*t));}double check(double x){ double maxx=0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { maxx=max(maxx,dis(a[i],a[j],x)); } } return maxx;}int main(){ int T,t=1;scanf("%d",&T); while(T--){ double maxx=-1; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].vx,&a[i].vy); double l=0,r=1e6; while(l+les<=r){ double mid=(l+r)*0.5; double midd=(mid+r)*0.5; if(check(mid)<check(midd)) r=midd; else l=mid; } printf("Case #%d: ",t++); if(n==1) printf("0.00 0.00\n"); else printf("%.2f %.2f\n",l,check(l) ); }}
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 移动端适配基础总结
- 把排序数组转换为高度最小的二叉搜索树
- FXS(le88266)工作原理介绍
- 初写简历的苦恼
- 二维数组的列交换
- 文章标题
- c++中cout和cerr的区别
- [LeetCode题解]455. Assign Cookies
- js的单线程和异步
- 【矩阵快速幂】 hdu5015 233Matrix
- java的继承 多态 类和接口
- C#136课的主要内容
- PHP实现的版本号比较
- Ecshop模板开发(十七):商城页面底部帮助信息