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 ...
随机推荐
- java- 枚举的常见用法
用法一:常量 public enum MyColor{Red,Black,Blue} public enum Color { RED, GREEN, BLANK, YELLOW } enum为枚举类的 ...
- bootstrap 正则表达式
<asp:TextBox runat="server" title="邮箱正确格式:xxx@xxx.xxx" class="form-cont ...
- 利用ORACLE ADV 功能完成SQL TUNING 调优(顾问培训) “让DBA失业还是解脱?”
oracle自动判断SQL性能功能. 11G的ADV,建议.SNAPSHOT,数据集合, 存储在oracle sys $_开头的表(10几条). 创建SNAPSHOT时选择天数, 默认14天. sq ...
- HDU_2156 分数矩阵
Problem Description 我们定义如下矩阵: 1/1 1/2 1/3 1/2 1/1 1/2 1 ...
- bzoj3571: [Hnoi2014]画框 最小乘积匹配+最小乘积XX总结,
思路大概同bzoj2395(传送门:http://www.cnblogs.com/DUXT/p/5739864.html),还是将每一种匹配方案的Σai看成x,Σbi看成y,然后将每种方案转化为平面上 ...
- Moving Tables
Moving Tables Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- 【原创】Android开发之ADB及ADB SHELl命令的应用
adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具.adb的工作方式比 ...
- C# 制作卸载文件
1.建一个控制台应用程序Uninstall: 2.在应用程序的mian方法中添加 static void Main(string[] args) { System.Diagnostics.Proces ...
- 【python之旅】python的基础三
目录: 1.装饰器 2.迭代器&生成器 3.Json & pickle 数据序列化 4.软件目录结构规范 一.装饰器 定义:本质是函数,(装饰其他函数)就是为其他函数添加附加功能 原 ...
- Django生产环境的部署-Apache-mod_wsgi
httpd.conf配置 ServerSignature On ServerTokens Full Define APACHE24 Apache2.4 Define SERVER_BASE_DIR & ...