HDU 5935
来源:互联网 发布:上海淘宝公司招人 编辑:程序博客网 时间:2024/06/11 21:55
Car
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2701 Accepted Submission(s): 728
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 recordN 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.
Of course, his speeding caught the attention of the traffic police. Police record
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 integersN , which is the number of the recorded positions.
The second line containsN numbers a1 , a2 , ⋯ , aN , indicating the recorded positions.
Limits
1≤T≤100
1≤N≤105
0<ai≤109
ai<ai+1
Every test case begins with an integers
The second line contains
Limits
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
136 11 21
Sample Output
Case #1: 4
Source
2016年中国大学生程序设计竞赛(杭州)
题意:
在n个点上有摄像头,进过这几个点的时间必须是整数,你从0秒开始,0点开始。速度只能增加或不变,求用时最少。
POINT:
从最后往前推,最后的速度肯定是V=x[n]-x[n-1] m/s,让最后一段用时1秒,然后用这个速度去比较前面一段,看看能不能整除,不能整除就在(x[n-1]-x[n-2])/V的时间上向上取整。在算出这个速度。重复做这个操作。O(n)
#include<iostream>#include<cstring>#include<cmath>#include<iomanip>using namespace std;#define ll long long int#define inf 0x7fffffffconst int maxn = 1e5 + 10;const double eps = 0.00000001;double dp[maxn];int c[maxn];int main(){int T;int n;int cs = 0;scanf("%d", &T);while (T--){cs++;memset(dp, 0, sizeof(dp));memset(c, 0, sizeof(c));scanf("%d", &n);for (int i = 1; i <= n; i++){scanf("%d", &c[i]);dp[i] = c[i] - c[i - 1];}double Speed = dp[n];int cnt = 1;for (int i = n - 1; i >= 1; i--){double Tmp = dp[i] / Speed;if (fabs(Tmp-(int)Tmp)<=eps){cnt = cnt + (int)Tmp;}else{cnt = cnt + (int)Tmp + 1;Speed = dp[i] / ((int)Tmp + 1);}}printf("Case #%d: %d\n", cs, cnt);}return 0;}
阅读全文
0 0
- HDU 5935
- hdu 5935 Car【贪心】
- hdu 5935 Car
- HDU 5935 Car (模拟)
- hdu 5935 Car
- HDU 5935 Car 贪心
- HDU-5935-Car
- hdu 5935 Car
- HDU 5935 Car
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- 结构型模式之组合模式
- 动态sql
- Oracle EBS Interface/API(8)-标准展BOM存储过程
- UnityShader实例06:UV动画
- Python实现网络图节点大小随度数变化
- HDU 5935
- 浏览器加载、解析、渲染的过程
- log4cpp简单使用
- APICloud 开发app 之 工具:Sublime插件
- 802.11协议帧格式、Wi-Fi连接交互过程、无线破解入门研究
- 阿里云centos7.2安装mysql-5.7.20
- HTTP协议
- 类,超类和子类(一)
- 拦截器学习