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

Hint

In the ?rst sample, Ted moves from 2 to 4 in 1 time unit. The speed 2/1 is maximal. In the second sample, Ted moves from 5 to 0 in 1 time unit. The speed 5/1 is maximal.

  水题,秒A。

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <cmath>
 6 using namespace std;
 7 const int N=1000010;
 8 int tim[N],pos[N],p[N];
 9 bool cmp(int x,int y){
10     return tim[x]<tim[y];
11 }
12 int main(){
13     int T,n,cas=0;
14     double ans;
15     scanf("%d",&T);
16     while(T--){
17         scanf("%d",&n);
18         for(int i=1;i<=n;i++){
19             scanf("%d%d",&tim[i],&pos[i]);
20             p[i]=i;
21         }
22         sort(p+1,p+n+1,cmp);
23         ans=0.0;
24         for(int i=2;i<=n;i++)
25             ans=max(ans,fabs(pos[p[i]]-pos[p[i-1]])/fabs(tim[p[i]]-tim[p[i-1]]));
26         printf("Case #%d: %.2f\n",++cas,ans);
27     }
28     return 0;
29 }
时间: 2024-10-07 17:43:15

水题:HDU 5112 A Curious Matt的相关文章

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 (水题)

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

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

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

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 1012 u Calculate e

题意 求n=0~9时的sigma(1/n!) 分析 因为刚学c++ 所以对浮点操作还是很不熟练,正好来了这么一道题 Accepted Code 1 /* 2 PROBLEM:hdu 1012 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 #include<iostream> 7 #include<iomanip> 8 using namespace std; 9 double a[10]; 10 int main() 11 { 12 cout<&l

水题/hdu 1004 Let the Balloon Rise

题意 给出n个字符串,输出出现次数最多的那个 分析 存下字符串后排序,再统计,输出 Accepted Code 1 /* 2 PROBLEM:hdu1004 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 7 #include<iostream> 8 #include<cstring> 9 #include<string> 10 #include<algorithm> 11 using namespace std; 12 13 in

水题/hdu 1001 Sum Problem

题意 给出一个数n,求1+2+??+n=? 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1001 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 9 int main() 10 { 11 int n; 12 while (scanf("%d",&n)!=EOF) 13 { 14 int s=0; 15 for (int i=1;i<=n;i++) s+=

水题/hdu 1000 A + B problem

题意 输入a,b,输出a+b: 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1000 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 int main() 9 { 10 int a,b; 11 while (scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b); 12 return 0; 13 }