HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
Car
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25 Accepted Submission(s): 12Problem DescriptionRuins 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.
InputFirst 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+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 Input1
3
6 11 21Sample OutputCase #1: 4SourceRecommend
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5935
题目大意:
一辆车,从t=0开始走,速度只能递增,可为小数。警察在t为整数的时候记录了N个车的位置(整数),问到达最后一个位置时这辆车总共开了多久。
题目思路:
【模拟】
首先可以知道答案必为整数,并且每一段距离都是匀速的。
从后往前看,最后一段距离X[N]-X[N-1]必然花了t=1s的时间(没有约束条件,速度可以任意加),V=X[N]-X[N-1]。
那么在它之前的距离X‘,只要满足速度V‘<V即可,那么把X’均分成t段,每段时间为1,行走距离V‘,只要V’*t恰好>X‘即可。
这样往前递推,每一段的速度都不能超过前面。
注意精度问题。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int a[N];
double v;
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
ans=;
printf("Case #%d: ",cass);
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&a[i]);
v=a[n]-a[n-];
for(i=n-;i;i--)
{
x=a[i]-a[i-];
if(x<=v+eps)
{
v=x;
ans++;
}
else
{
ans+=(int(double(x-eps)/v)+);
v=(double(x)/(int(double(x-eps)/v)+));
}
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/
HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))的更多相关文章
- HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))
扫雷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))
ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1009 HDU 5969
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...
- HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
- HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- iOS-开发日志-UIimageView
UIImageView属性 1.Image 设置图片,默认显示 UIImageView *_imageView = [[UIImageView alloc]init]; _imageView. ...
- @Resource注解省略name属性后的行为
@Resource有一个name属性,该属性值为所要注入的Bean实例的id,类似于<property.../>元素的ref属性,不过在spring中允许省略name属性值,省略后在以下情 ...
- javascript 中caller,callee,call,apply 的概念[转载]
在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments : 该对象代表正在执行的函数和调用它的函数的参数. [function.]argument ...
- 一次ora-1113 记录
记录博客园的第一天,今天在电脑前发呆,突然感觉自己记忆越来越差,近年来随着工作力度的加强,感觉自己越来越力不从心,问题重复的出现.感觉自己应该去记录点什么了,随选择了用写博客的方式记录一下.第一天先记 ...
- localstorage 使用
localstorage作为HTML5的一个特殊属性,在发布时就备受关注:最近总结了其一些小的用法,希望可以抛砖引玉. 因HTML5本地存储只能存字符串,所以所有数据存储的话,都要转化成字符串:而js ...
- 诡异的XmlSerializer属性字段Specified
自动生成代码时,往往会为一个字段假设为 * , 生成另一个bool型字段: *Specified: 如: [Serializable] public class A { [XmlElement] pu ...
- hadoop1 和haddop2 mapperreducer的wordcount详解
转 mapreduce中wordcount详细介绍(包括hadoop1和hadoop2版本) 发表于1年前(2014-04-24 10:08) 阅读(1458) | 评论(0) 1人收藏此文章, ...
- 坑爹的NSIS转义符:$ (在NSIS的MessageBox中写换行文字)
最近的项目中,发现了NSIS一个比较坑的地方:$ 不但是变量常量的开头,还是一个转义字符. 大家有没有发现,NSIS写的脚本中,如果要让弹出消息框中的文字带换行功能,“\r\n” 是不是很不管用呢? ...
- STM32学习内容和计划
一.STM32学习内容(流程) 1.学习STM32开发流程 ①MDK使用.建立工程.调试等 ②库开发方法 2.学习STM32常用外设开发 ①GPIO ②中断 ③定时器 ④串口 ⑤CAN 3.学习STM ...
- hdu 4111 Alice and Bob
组合游戏题: 组合游戏的规则: 1.必败态的所有后继都是必胜态: 2.必胜态最少有一个必败的后继: 这里的必胜态是f[1][0][0][0]; 其中f[a][b][c][d]表示有a个1,b个2,c个 ...