admin管理员组

文章数量:1612098

Problem 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 ≤ N ≤ 10000),indicating the number of records.

Each of the following N lines contains two integers t i and x i (0 ≤ t i, x i ≤ 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 t i 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

    

   题意:给出n对点,分别表示时刻,和该时刻的速度,求最大加速度,任意时刻之间看成匀加速。

   思路:最大加速度一定在两个相邻的时刻里,画图很容易知道。所以排个序,然后一段一段的比较就行了。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 struct p
 7 {
 8     int f;
 9     double r;
10 };p b[10005];
11 bool com(p x,p y)
12 {
13     return x.f<y.f;
14 }
15 int main()
16 {
17     int t,n,i,k;
18     double ans,temp;
19     scanf("%d",&t);
20     for (k=1;k<=t;k++)
21     {
22         scanf("%d",&n);
23         for (i=0;i<n;i++) scanf("%d %lf",&b[i].f,&b[i].r);
24         sort(b,b+n,com);
25         ans=0;
26         for (i=1;i<n;i++)
27         {
28             temp=abs(b[i].r-b[i-1].r)/(b[i].f-b[i-1].f);
29             ans=max(ans,temp);
30         }
31         printf("Case #%d: %0.2lf\n",k,ans);
32     }
33     return 0;
34 }

 

转载于:https://wwwblogs/pblr/p/4828871.html

本文标签: hducurious水题Matt