hdu 5112 (2014北京现场赛 A题)
给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值
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
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <string> 6 # include <cmath> 7 # include <queue> 8 # include <list> 9 # define LL long long 10 using namespace std ; 11 12 struct point 13 { 14 int t ; 15 int v ; 16 }a[10010]; 17 18 bool cmp(point x , point y) 19 { 20 return x.t < y.t ; 21 } 22 23 int main() 24 { 25 //freopen("in.txt","r",stdin) ; 26 int T ; 27 scanf("%d" , &T) ; 28 int Case = 0 ; 29 while(T--) 30 { 31 int n , i ; 32 Case++ ; 33 double MAX = 0 ; 34 scanf("%d" , &n) ; 35 for (i = 0 ; i < n ; i++) 36 scanf("%d %d" , &a[i].t , &a[i].v) ; 37 sort(a , a+n , cmp) ; 38 for (i = 0 ; i < n-1 ; i++) 39 { 40 double ans = fabs((a[i+1].v - a[i].v)*1.0/(a[i+1].t - a[i].t)*1.0) ; 41 if (ans > MAX) 42 MAX = ans ; 43 } 44 printf("Case #%d: %.2lf\n" , Case , MAX) ; 45 46 } 47 48 return 0 ; 49 }