转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

 

下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜。

先将这五题的题解放上来,剩余题目等搞出来再补上

A题

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)


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
Hint
In the first 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.

题目要求求出最大的速度

分析:以时间为key值,排序,然后遍历一遍

 1 #include <iostream>
 2 #include <cstring>
 3 #include <iomanip>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 int a[10010];
 8 int b[10010];
 9 double c[10010];
10 int id[10010];
11 bool cmp(int x,int y)
12 {
13     return a[x]<=a[y];
14 }
15 int main()
16 {
17     ios::sync_with_stdio(false);
18     int t;
19     int n;
20     int cas=1;
21     cin>>t;
22     while(t--)
23     {
24         cin>>n;
25         a[0]=0,b[0]=0;
26         for(int i=0;i<n;i++)
27         {
28             cin>>a[i]>>b[i];
29             id[i]=i;
30         }
31         sort(id,id+n,cmp);
32         double maxx=0;
33         for(int i=1;i<n;i++)
34         {
35             maxx=max(maxx,fabs((b[id[i]]-b[id[i-1]])*1.0/((a[id[i]]-a[id[i-1]])*1.0)));
36         }
37         cout<<"Case #"<<cas++<<": ";
38         cout<<fixed<<setprecision(2)<<maxx<<endl;
39     }
40     return 0;
41 }
代码君

相关文章:

  • 2021-05-11
  • 2021-08-17
  • 2021-12-30
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案