zoukankan      html  css  js  c++  java
  • Car HDU

    Problem Description
    Ruins is driving a car to participating in a programming contest. As on a very tight schedule, he will drive the car without any slow down, so the speed of the car is non-decrease real number.

    Of course, his speeding caught the attention of the traffic police. Police record N positions of Ruins without time mark, the only thing they know is every position is recorded at an integer time point and Ruins started at 0 .

    Now they want to know the minimum time that Ruins used to pass the last position.
     
    Input
    First line contains an integer T , which indicates the number of test cases.

    Every test case begins with an integers N , which is the number of the recorded positions.

    The second line contains N numbers a1 , a2 , , aN , indicating the recorded positions.

    Limits
    1T100
    1N105
    0<ai109
    ai<ai+1
     
    Output
    For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the minimum time.
     
    Sample Input
    1 3 6 11 21
     
    Sample Output
    Case #1: 4
     

    废墟正在开车参加编程比赛。 由于时间非常紧张,他会在没有任何减速的情况下驾驶赛车,因此赛车的速度是非减少的实数。

    当然,他的超速驾驶引起了交警的注意。 警方在没有时间标记的情况下记录了N个遗址的废墟位置,他们知道的每一个位置唯一的记录是在整数时间点记录的,废墟从0开始记录。

    现在他们想知道遗迹用于通过最后位置的最短时间。

    这题是个想法题,速度递增 先算出速度的最大值 速度可以为小数,

    当速度不等时,可以略微的下调速度  b=temp/(t+1);

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<queue>
     6 #include<set>
     7 #include<cctype>
     8 using namespace std;
     9 int a[100010];
    10 int main() {
    11     int t,cas=1,n;
    12     scanf("%d",&t);
    13     while(t--) {
    14         scanf("%d",&n);
    15         for (int i=0 ; i<n ; i++)
    16             scanf("%d",&a[i]);
    17         long long ans=0;
    18         double b=a[n-1]-a[n-2];
    19         for (int i=n-1 ; i>=1 ; i--) {
    20             double  temp=(a[i]-a[i-1])*1.0;
    21             int t=temp/b;
    22             ans+=t;
    23             if (temp/t!=b) {
    24                 ans++;
    25                 b=temp/(t+1);
    26             }
    27         }
    28         printf("Case #%d: %d
    ",cas++,ans);
    29     }
    30     return 0;
    31 }
     
  • 相关阅读:
    自定义字体(特殊字体)在网页中的应用
    面向对象中的接口和多态
    抽象类和抽象方法
    python简单的函数定义和用法实例
    python简单的函数定义和用法实例
    Python变量和字符串详解
    Python变量和字符串详解
    大数据产业发展 三大模式可毕其功于一役
    大数据产业发展 三大模式可毕其功于一役
    python实现基于两张图片生成圆角图标效果的方法
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8530936.html
Copyright © 2011-2022 走看看