码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5112 A Curious Matt

时间:2015-06-27 16:12:13      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

题目连接

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

 

hdu 5112 A Curious Matt

标签:

原文地址:http://www.cnblogs.com/GadyPu/p/4604126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!