hdu 5112 A Curious Matt (水题)

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 ti and xi (0 ≤ ti, xi ≤ 106), 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

题意:给出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 }
时间: 2024-11-12 23:01:16

hdu 5112 A Curious Matt (水题)的相关文章

HDOJ 5112 A Curious Matt 水题

A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 64    Accepted Submission(s): 49 Problem Description There is a curious man called Matt. One day, Matt's best friend Ted is wand

水题:HDU 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’

HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)

A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 3058    Accepted Submission(s): 1716 Problem Description There is a curious man called Matt. One day, Matt's best friend Ted is w

hdu 5112 A Curious Matt

http://acm.hdu.edu.cn/showproblem.php?pid=5112 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int t; 7 int n; 8 struct node 9 { 10 int t,x; 11 bool operator<(const node &a)const 12 { 13

hdu 1999 不可摸数 水题。

不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7966    Accepted Submission(s): 2024 Problem Description s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数. Input 包

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

HDU 5590 ZYB&#39;s Biology 水题

ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5590 Description ZYB(ZJ−267)在NOIP拿到600分之后开始虐生物题,他现在扔给你一道简单的生物题:给出一个DNA序列和一个RNA序列,问它们是否配对. DNA序列是仅由A,C,G,T组成的字符串,RNA序列是仅由A,C,G,U组成的字符串. DNA和RNA匹配当且仅当每

hdoj 5112 A Curious Matt

A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 1338    Accepted Submission(s): 735 Problem Description There is a curious man called Matt. One day, Matt's best friend Ted is wa

hdu 4847 Wow! Such Doge! 水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 统计文本中一共有多少个“Doge” 水题 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #includ