HDU 5935 Car(思维,模拟,精度)
2016-11-04 13:03
288 查看
Total Submission(s): 523 Accepted Submission(s): 185
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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
1≤T≤100
1≤N≤105
0<ai≤109
ai<ai+1
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
1
3
6 11 21
[align=left]Sample Output[/align]
Case #1: 4
题意:,给出n个点坐标,一辆车以不递减的速度行驶,路过每一个点的时间都是整数,问最短的时间。
题解:
刚上手感觉没法做的样子,后来倒着想。因为每过一个点的时间都是整数,求最短时间,所以最后一段所用的时间一定是1s
这样我们可以求得最后一段的速度。则前一段的速度<=这段的速度,时间=前一段的距离/这段的速度,向上取整,注意精度问题,用分数表示速度。
代码:
Car
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 523 Accepted Submission(s): 185
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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
1≤T≤100
1≤N≤105
0<ai≤109
ai<ai+1
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
1
3
6 11 21
[align=left]Sample Output[/align]
Case #1: 4
题意:,给出n个点坐标,一辆车以不递减的速度行驶,路过每一个点的时间都是整数,问最短的时间。
题解:
刚上手感觉没法做的样子,后来倒着想。因为每过一个点的时间都是整数,求最短时间,所以最后一段所用的时间一定是1s
这样我们可以求得最后一段的速度。则前一段的速度<=这段的速度,时间=前一段的距离/这段的速度,向上取整,注意精度问题,用分数表示速度。
代码:
#include <bits/stdc++.h> #define ll long long using namespace std; const int N=1e5+10; ll a ; int T,n; int main() { scanf("%d",&T); for(int i=1;i<=T;i++) { printf("Case #%d: ",i); scanf("%d",&n); for(int j=1;j<=n;j++) { scanf("%I64d",&a[j]); } ll output=0; ll fenmu,fenzi; for(int j=n;j>=1;j--) { if(j==n) { output++; fenzi=a[j]-a[j-1]; fenmu=1; } else { ll dis=a[j]-a[j-1]; fenmu*=dis; swap(fenzi,fenmu); ll tmp=fenzi/fenmu+1; if(fenzi%fenmu==0) tmp--; output+=tmp; fenzi=dis; fenmu=tmp; } } printf("%I64d\n",output); } }
相关文章推荐
- HDU 5935 Car(模拟+精度)
- hdoj 5935 Car (模拟, 精度)
- HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
- HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
- HDU 5935 Car (模拟)
- hdu 5935 Car
- HDU 5935 Car 贪心 倒推 分数
- HDU 5935 Car 贪心
- hdu 5935 Car
- hdu 5935 Car【贪心】
- HDU 5538 House Building(模拟——思维)
- hdu 5170 GTY's math problem【精度控制】【思维】
- HDU 6215 Brute Force Sorting(模拟链表 思维)
- HDU 5122 K.Bro Sorting (14北京 思维模拟)
- HDU 6058 Kanade's sum 思维+ 模拟链表
- HDU 5935 && 2016CCPC杭州 C: Car
- Hdu 4803 Poor Warehouse Keeper(从1,1变为x,y,精度+思维)
- hdu 5532 Almost Sorted Array【思维+模拟】
- 2016ccpc杭州赛 hdu 5935 C.Car
- HDU 5935 Car (贪心)——2016年中国大学生程序设计竞赛(杭州)