zoukankan      html  css  js  c++  java
  • hdu 5112 A Curious Matt

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=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 leq N leq 10000)$,indicating the number of records.

    Each of the following $N$ lines contains two integers $t_i$ and $x_i$ $(0 leq t_i, x_i leq 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 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

    简单题,权当练习一下英文。。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<map>
     8 using std::max;
     9 using std::cin;
    10 using std::cout;
    11 using std::endl;
    12 using std::fabs;
    13 using std::sort;
    14 using std::pair;
    15 using std::vector;
    16 #define pb(e) push_back(e)
    17 #define sz(c) (int)(c).size()
    18 #define mp(a, b) make_pair(a, b)
    19 #define all(c) (c).begin(), (c).end()
    20 #define iter(c) decltype((c).begin())
    21 #define cls(arr,val) memset(arr,val,sizeof(arr))
    22 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    23 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    24 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    25 const int N = 10010;
    26 typedef unsigned long long ull;
    27 struct Node {
    28     int t, x;
    29     bool operator<(const Node &b) const {
    30         return t < b.t;
    31     }
    32 }rec[N];
    33 int main() {
    34 #ifdef LOCAL
    35     freopen("in.txt", "r", stdin);
    36     freopen("out.txt", "w+", stdout);
    37 #endif
    38     int t, n, k = 1;
    39     scanf("%d", &t);
    40     while (t--) {
    41         double ans = 0.0;
    42         scanf("%d", &n);
    43         rep(i, n) scanf("%d %d", &rec[i].t, &rec[i].x);
    44         sort(rec, rec + n);
    45         for (int i = 1; i < n; i++) {
    46             ans = max(ans, fabs((double)rec[i].x - rec[i - 1].x) / (rec[i].t - rec[i - 1].t));
    47         }
    48         printf("Case #%d: %.2lf
    ", k++, ans);
    49     }
    50     return 0;
    51 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    WSL配置c语言环境
    vue无法获取$store中的变量
    接口自动化中全局参数以及用例信息
    正则表达式
    vue-i18n web 前端国际化
    elementui默认样式修改的问题
    setTimeOut的使用以及this指向问题
    elementui 在表格表头里面添加按钮
    各种
    element ui tabs标签页动态增加标签页,标签页引用组件
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4604126.html
Copyright © 2011-2022 走看看