zoukankan      html  css  js  c++  java
  • HDU5037(SummerTrainingDay01-C)

    Frog

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 4467    Accepted Submission(s): 1069


    Problem Description

    Once upon a time, there is a little frog called Matt. One day, he came to a river.

    The river could be considered as an axis.Matt is standing on the left bank now (at position 0). He wants to cross the river, reach the right bank (at position M). But Matt could only jump for at most L units, for example from 0 to L.

    As the God of Nature, you must save this poor frog.There are N rocks lying in the river initially. The size of the rock is negligible. So it can be indicated by a point in the axis. Matt can jump to or from a rock as well as the bank.

    You don't want to make the things that easy. So you will put some new rocks into the river such that Matt could jump over the river in maximal steps.And you don't care the number of rocks you add since you are the God.

    Note that Matt is so clever that he always choose the optimal way after you put down all the rocks.
     

    Input

    The first line contains only one integer T, which indicates the number of test cases.

    For each test case, the first line contains N, M, L (0<=N<=2*10^5,1<=M<=10^9, 1<=L<=10^9).

    And in the following N lines, each line contains one integer within (0, M) indicating the position of rock.
     

    Output

    For each test case, just output one line “Case #x: y", where x is the case number (starting from 1) and y is the maximal number of steps Matt should jump.
     

     

    Sample Input

    2
    1 10 5
    5
    2 10 3
    3
    6
     

     

    Sample Output

    Case #1: 2
    Case #2: 4
     

    Source

     
     1 //2017-10-08
     2 #include <cstdio>
     3 #include <iostream>
     4 #include <cstring>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 const int N = 200010;
    10 int arr[N], n, m, l, ans, T;
    11 
    12 int main(){
    13     int kase = 0;
    14     scanf("%d", &T);
    15     while(T--){
    16         scanf("%d%d%d", &n, &m, &l);
    17         arr[0] = 0;
    18         arr[n+1] = m;
    19         for(int i = 1; i <= n; i++)
    20             scanf("%d", &arr[i]);
    21         sort(arr, arr+n+1);
    22         ans = 0;
    23         int k = l;
    24         for(int i = 1; i <= n+1; i++){
    25             int a = (arr[i]-arr[i-1])%(l+1);
    26             int b = (arr[i]-arr[i-1])/(l+1);
    27             if(a+k >= l+1){
    28                 k = a;
    29                 ans += 2*b+1;
    30             }else{
    31                 k += a;
    32                 ans += 2*b;
    33             }
    34         }
    35         cout<<"Case #"<<++kase<<": "<<ans<<endl;
    36     }
    37 
    38     return 0;
    39 }
  • 相关阅读:
    ASP.NET MVC中获取URL地址参数的两种写法
    SQL Server之存储过程基础知识
    ASP.NET MVC 四种Controller向View传值方法
    Js数据类型、Json格式、Json对象、Json字符串
    调用微信内置的方法及wx.config的配置问题
    ref和out的使用及区别
    ASP.NET MVC post请求接收参数的三种方式
    Asp.Net Mvc 路由机制
    Asp.Net MVC中Action跳转小结
    JS应用MD5散列计算头像URL
  • 原文地址:https://www.cnblogs.com/Penn000/p/7637370.html
Copyright © 2011-2022 走看看