zoukankan      html  css  js  c++  java
  • 水题: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 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.
     
      水题,秒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
    ",++cas,ans);
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    扩展中国剩余定理
    bzoj 3816&&uoj #41. [清华集训2014]矩阵变换
    THUSC2017
    bzoj 4521: [Cqoi2016]手机号码
    bzoj 4871: [Shoi2017]摧毁“树状图”
    bzoj 2300 : [HAOI2011]防线修建
    bzoj 3853 : GCD Array
    HEOI 2017 游记
    bzoj3926: [Zjoi2015]诸神眷顾的幻想乡 广义后缀自动机模板
    bzoj 4310 跳蚤
  • 原文地址:https://www.cnblogs.com/TenderRun/p/5943355.html
Copyright © 2011-2022 走看看