hdu 5112 (2014北京现场赛 A题)

时间:2022-01-20 19:36:14

给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值

Sample Input
2
3 // n
2 2 //t v
1 1
3 4
3
0 3
1 5
2 0

Sample Output
Case #1: 2.00
Case #2: 5.00

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ; struct point
{
int t ;
int v ;
}a[]; bool cmp(point x , point y)
{
return x.t < y.t ;
} int main()
{
//freopen("in.txt","r",stdin) ;
int T ;
scanf("%d" , &T) ;
int Case = ;
while(T--)
{
int n , i ;
Case++ ;
double MAX = ;
scanf("%d" , &n) ;
for (i = ; i < n ; i++)
scanf("%d %d" , &a[i].t , &a[i].v) ;
sort(a , a+n , cmp) ;
for (i = ; i < n- ; i++)
{
double ans = fabs((a[i+].v - a[i].v)*1.0/(a[i+].t - a[i].t)*1.0) ;
if (ans > MAX)
MAX = ans ;
}
printf("Case #%d: %.2lf\n" , Case , MAX) ; } return ;
}