zoukankan      html  css  js  c++  java
  • 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
    ",k,ans);
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    牛客-Python-字符流中第一个不重复的字符
    牛客网-python-表示数值的字符串
    牛客网-(标星)正则表达式的匹配
    牛客网-构建乘积数组
    牛客网-和为S的两个数字
    new code-和为S的连续正数序列
    newcode-平衡二叉树
    Reinforcement Learning学习笔记|Deep Q-learning算法
    Reinforcement Learning学习笔记|Q-learning算法
    C++|重拾|笔记20190307
  • 原文地址:https://www.cnblogs.com/pblr/p/4828871.html
Copyright © 2011-2022 走看看