Car HDU - 5935

时间:2023-03-09 07:24:19
Car HDU - 5935
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 NCar HDU - 5935

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 0Car HDU - 5935

.

Now they want to know the minimum time that Ruins used to pass the last position.

Input
First line contains an integer TCar HDU - 5935

, which indicates the number of test cases.

Every test case begins with an integers NCar HDU - 5935

, which is the number of the recorded positions.

The second line contains NCar HDU - 5935

numbers aCar HDU - 59351Car HDU - 5935Car HDU - 5935

, aCar HDU - 59352Car HDU - 5935Car HDU - 5935

, ⋯Car HDU - 5935

, aCar HDU - 5935NCar HDU - 5935Car HDU - 5935

, indicating the recorded positions.

Limits
1≤T≤100Car HDU - 5935

1≤N≤10Car HDU - 59355Car HDU - 5935Car HDU - 5935

0<ai≤10Car HDU - 59359Car HDU - 5935Car HDU - 5935

aCar HDU - 5935iCar HDU - 5935<aCar HDU - 5935i+1Car HDU - 5935Car HDU - 5935

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);

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<cctype>
using namespace std;
int a[];
int main() {
int t,cas=,n;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for (int i= ; i<n ; i++)
scanf("%d",&a[i]);
long long ans=;
double b=a[n-]-a[n-];
for (int i=n- ; i>= ; i--) {
double temp=(a[i]-a[i-])*1.0;
int t=temp/b;
ans+=t;
if (temp/t!=b) {
ans++;
b=temp/(t+);
}
}
printf("Case #%d: %d\n",cas++,ans);
}
return ;
}