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 }
  • 相关阅读:
    基于Spring+SpringMVC实现AOP日志记录功能service注入异常为null的解决办法
    关于SpringBoot项目打包没有把依赖的jar包一起打包的解决办法
    JavaFx项目打包成exe,并集成Jre,使Java项目在任意机器运行
    常用正则表达式
    SqlServer 2005及其以上版本能用的查询数据的行号
    js 中的倒计时功能
    数据库删除重复列
    【转】svn文件清除批处理工具
    JS获取当前页面名称
    sql 去除重复记录
  • 原文地址:https://www.cnblogs.com/pblr/p/4828871.html
Copyright © 2011-2022 走看看