hdu 5112 A Curious Matt

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5112

 A Curious Matt

Description

There is a curious man called Matt.

One day, Matt's best friend Ted is wandering on the non-negative half of the number line. Matt finds it interesting to know the maximal speed Ted may reach. In order to do so, Matt takes records of Ted’s position. Now Matt has a great deal of records. Please help him to find out the maximal speed Ted may reach, assuming Ted moves with a constant speed between two consecutive records.

Input

The first line contains only one integer $T$, which indicates the number of test cases.

For each test case, the first line contains an integer $N\  (2 \leq N \leq 10000)$,indicating the number of records.

Each of the following $N$ lines contains two integers $t_i$ and $x_i$ $(0 \leq t_i, x_i \leq 10^6)$, indicating the time when this record is taken and Ted’s corresponding position. Note that records may be unsorted by time. It’s guaranteed that all ti would be distinct.

Output

For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1), and y is the maximal speed Ted may reach. The result should be rounded to two decimal places.

Sample Input

2
3
2 2
1 1
3 4
3
0 3
1 5
2 0

Sample Output

Case #1: 2.00
Case #2: 5.00

简单题,权当练习一下英文。。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 using std::max;
 9 using std::cin;
10 using std::cout;
11 using std::endl;
12 using std::fabs;
13 using std::sort;
14 using std::pair;
15 using std::vector;
16 #define pb(e) push_back(e)
17 #define sz(c) (int)(c).size()
18 #define mp(a, b) make_pair(a, b)
19 #define all(c) (c).begin(), (c).end()
20 #define iter(c) decltype((c).begin())
21 #define cls(arr,val) memset(arr,val,sizeof(arr))
22 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
23 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
24 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
25 const int N = 10010;
26 typedef unsigned long long ull;
27 struct Node {
28     int t, x;
29     bool operator<(const Node &b) const {
30         return t < b.t;
31     }
32 }rec[N];
33 int main() {
34 #ifdef LOCAL
35     freopen("in.txt", "r", stdin);
36     freopen("out.txt", "w+", stdout);
37 #endif
38     int t, n, k = 1;
39     scanf("%d", &t);
40     while (t--) {
41         double ans = 0.0;
42         scanf("%d", &n);
43         rep(i, n) scanf("%d %d", &rec[i].t, &rec[i].x);
44         sort(rec, rec + n);
45         for (int i = 1; i < n; i++) {
46             ans = max(ans, fabs((double)rec[i].x - rec[i - 1].x) / (rec[i].t - rec[i - 1].t));
47         }
48         printf("Case #%d: %.2lf\n", k++, ans);
49     }
50     return 0;
51 }
View Code

 

转载于:https://www.cnblogs.com/GadyPu/p/4604126.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值