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 }
View Code

 

转载于:https://www.cnblogs.com/mengchunchen/p/4850711.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值