# Car HDU – 5935

0 6 11 21

11-21这一段时间是1；

6-11这一段因为速度不能超过后一段，所以时间也是1；

0-6这一段如果时间是1的话那么速度就会超过第二段，所以时间是2；

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 NN 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 00 .

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

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

The second line contains NN numbers a1a1 , a2a2 , , aNaN , indicating the recorded positions.

Limits
1T1001≤T≤100
1N1051≤N≤105
0<ai1090<ai≤109
ai<ai+1ai<ai+1OutputFor 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
#include<iostream>
#include<cstdio>
using namespace std;
int a[100010];
int num=1;
int main(){
int t;
cin>>t;
a[0]=0;
while(t--){
int n;

cin>>n;
n++;
for(int i=1;i<n;i++){
scanf("%d",&a[i]);
}
int time=1;
long long  alltime=1;
int pre;
for(int i=n-2;i>0;i--){
pre=time;
time=((double)(a[i]-a[i-1])*time)/(double)(a[i+1]-a[i]);
if((a[i+1]-a[i])*time!=(a[i]-a[i-1])*pre){
time++;
}
alltime+=time;
}
printf("Case #%d: %lld\n",num++,alltime);

}

return 0;
} 

• qwq

2017年4月5日 下午11:02

哈哈哈qwq