hdu 5112 (2014北京 水)

时间:2022-03-10 00:39:41

题意:有个人在跑步,一直每个时间他所在的位置,求最大速度

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; struct node
{
int t;
int dis;
}pnode[100005]; bool cmp(node a,node b)
{
return a.t < b.t;
} int main()
{
int T,n;
scanf("%d",&T);
int cas = 1;
while(T--)
{
scanf("%d",&n);
double ans = 0;
for(int i = 0;i < n;i++)
{
scanf("%d%d",&pnode[i].t,&pnode[i].dis);
}
sort(pnode,pnode+n,cmp);
for(int i = 1;i <= n;i++)
{
double tdis = (double)pnode[i].dis - pnode[i-1].dis;
if(tdis < 0)
tdis = -tdis;
double tt = (double)pnode[i].t - pnode[i-1].t;
ans = max(ans,tdis/tt);
}
printf("Case #%d: %.2lf\n",cas++,ans);
}
return 0;
}