【C++】向上、向下取整函数
C/C++ 取整函数ceil(),floor(),向上取整,向下取整

C-Car

原题链接

题解链接

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.

Input
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

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

1
3
6 11 21

Sample Output

Case #1: 4

题意:
一辆汽车从0点开始出发,给你几个他的时间点到达的地点,但这几个时间点不一定是连续的,问你到达给出的最后一个时间点所花费的时间为多少,对于速度有个要求:后一秒走的路程比大于等于前一秒
1.经过题中给出的地点时,时间点要为整数,车速要非递减
2.就是让车一直加速,但加速度可变,并且在经过题中给出的两点之间距离时用了整数的时间

思路:
在到达最后一个地点时,速度达到最大
经过最后一段路程时,时间为1
所以从后往前推时间和速度
前一段距离的速度 <= 后一段距离的速度

赛后补题:AC
参考了下题解

#include <iostream>
#include <bits/stdc++.h>
using namespace std;int main()
{int t,n;scanf("%d",&t);for(int k=1;k<=t;k++){long long int x[100005];scanf("%d",&n);x[0]=0;for(int i=1;i<=n;i++){scanf("%lld",&x[i]);}long long int sum=0,ti;for(int i=n;i>=1;i--){if(i==n)  ti=1;else{ti=(int)ceil((x[i]-x[i-1])*1.0*ti/(x[i+1]-x[i]));//向上取整}sum+=ti;// printf("***%d %f %d %d\n",x[i]-x[i-1],v,t,sum);}printf("Case #%d: %lld\n",k,sum);}return 0;
}

比赛时写的代码:WA
冗杂。。。


#include <bits/stdc++.h>using namespace std;int main()
{int t,n;scanf("%d",&t);for(int k=1; k<=t; k++){int st[100005]= {0};double v[100005]= {0};long long int tim[100005]= {0};long long int sum=0;scanf("%d",&n);int m=0;int x,y;scanf("%d",&x);if(n==0)sum=1;else{st[m++]=x;while(m<n){scanf("%d",&y);st[m++]=y-x;x=y;}for(int i=m-1; i>=0; i--){if(i==m-1){tim[i]=1;v[i]=st[i];}
//                else if(st[i]<st[i+1])
//                {//                    tim[i]=st[i]*1.0/v[i+1];
//                    if(tim[i]*v[i+1]!=st[i]) tim[i]++;
//                    v[i]=st[i]*1.0/tim[i];
//                }
//                else if(st[i]>=st[i+1])
//                {else{tim[i]=st[i]*1.0/v[i+1];if(tim[i]*v[i+1]!=st[i]) tim[i]++;v[i]=st[i]*1.0/tim[i];}
//                }sum+=tim[i];// printf("%d %.2f %lld\n",st[i],v[i],tim[i]);}}printf("Case #%d: %lld\n",k,sum);}
}

修改之后的代码:AC
精简版见文章开头的第一个代码

它这两个代码一个WA一个AC
主要问题就是:
1.long long int 的问题
2.每一段路程其速度的精度问题
解决:
2.不求速度,速度随用随算

#include <bits/stdc++.h>using namespace std;int main()
{int t,n;scanf("%d",&t);for(int k=1; k<=t; k++){int st[100005]= {0};long long int tim[100005]= {0};long long int sum=0;scanf("%d",&n);int m=0;int x,y;scanf("%d",&x);if(n==0)sum=1;else{st[m++]=x;while(m<n){scanf("%d",&y);st[m++]=y-x;x=y;}for(int i=m-1; i>=0; i--){if(i==m-1){tim[i]=1;}else{tim[i]=st[i]*1.0*tim[i+1]/st[i+1];if(tim[i]*st[i+1]/tim[i+1]!=st[i]) tim[i]++;}sum+=tim[i];//ceshi //printf("%d %.2f %lld\n",st[i],v[i],tim[i]);}}printf("Case #%d: %lld\n",k,sum);}
}

SDUT 2020 Autumn Team Contest---31(for 1819)--- C - Car相关推荐

  1. M - Maratona Brasileira de Popcorn(SDUT 2019 Autumn Team Contest 6th)

    M - Maratona Brasileira de Popcorn 解题思路: 核心思想:二分法+枚举 最少的天数为一天,最多的天数为所有数的总和.采用二分,如果中间这个天数下所需人数超出限制,则证 ...

  2. SDUT 2020 Summer Team Contest 2nd(for 19) BDJ题解

    点这里进入我的博客,获得更好的体验! 搜索框中搜索这篇博客即可,已做迁移,支持一下咯~ Clone from Regional Olympiad of Student St Petersburg, O ...

  3. MongoDB Server 3.4版本将于2020年1月31日停止支持

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源 | 公众号「Mongoing中文社区」 Mongo ...

  4. 全国各地区最低工资标准情况(截至2020年3月31日)

    人社部网站4月26日发布全国各地区最低工资标准情况(截至2020年3月31日),数据显示,上海月最低工资标准最高,为2480元:北京为2200元,广东为2100元,其中深圳为2200元.

  5. 《大数据》专题征文:医学大数据(截稿时间:2020年5月31日)

    医学大数据包含来自医疗.生物.医学研究等领域的各类数据,具有文本.数字.影像.视频与音频等多种形态特征,是典型的非结构化数据.分析和挖掘其中的价值信息对于人类健康和疾病诊断.分析与治疗具有重要的科学意 ...

  6. 2020年12月31日flash禁用后网页如何播放rtmp视频流

    2020年12月31日flash禁用后网页如何播放rtmp视频流 众所周知,2020年底flash将不再被各大浏览器支持,那么以前利用flash技术做的产品该怎么办呢?我就遇到了这样的问题. 公司有一 ...

  7. 2020 GDUT Rating Contest I (Div. 2) A.Cow Gymnastics

    来源 codeforces 2020 GDUT Rating Contest I (Div. 2) 题目: A. Cow Gymnastics In order to improve their ph ...

  8. 2020 GDUT Rating Contest III (Div2)

    2020 GDUT Rating Contest III (Div2) A Wormhole Sort 题意: 给出N个打乱顺序的数,和M条边(a,b,c)表示在a位置的数可以和在b位置的数交换,这条 ...

  9. Flash将在2020年12月31日退出历史舞台

    外媒 Winfuture 报道,Adobe 的 Flash 格式迅速从动画网络故事的英雄变成了网络广告的反派,让你的 PC 速度变慢,最终成为恶意软件的载体. 该 Flash 格式已经经历了二十年,该 ...

最新文章

  1. angular2 学习笔记 ( Rxjs, Promise, Async/Await 的区别 )
  2. SpringBoot2.0之 个性化Banner
  3. 3篇量子计算里程碑论文同登Nature封面:保真度超99%,达到实用化水平
  4. python监听鼠标事件_Python中使用PyHook监听鼠标和键盘事件实例
  5. STM32F030控制蜂鸣器
  6. SAP WM模块常用T-code
  7. 精讲23种设计模式-基于装饰模式~设计多级缓存框架
  8. 《网络攻防实践》 课程教学
  9. python如何提高程序可读性_Python规范:提高可读性
  10. Oracle 中文转五笔码
  11. DDOS高防IP作用,哪些地方需要用到高防IP
  12. 运营商价格战终于打起来了,中国联通也有19元套餐
  13. 电脑右下角,电脑右下角的小喇叭不见了怎么办【解决方法】
  14. 适合产品经理的桌面壁纸-分类神器
  15. linux卸载致远oa,致远oa(seeyon)文件上传漏洞重现及分析
  16. android java 面试题及答案_android面试题及答案
  17. 如何承接软件外包项目
  18. 真武三国java_2010年CPU第三季手机游戏风云榜TOP10名单
  19. 数据中心对洪水风险应具备应急措施
  20. mysql类似于excel的删除重复项_删除重复数据 excel去除重复数据 怎么筛选重复数据 excel重复数据合并...

热门文章

  1. 正大国际琪貨召主涨户:国债期货的投资模式是什么
  2. 苹果手机没声音了显示耳机模式_苹果iPhone 12信号存猫腻 智能数据模式下状态栏显示5G 实际是4G信号_手机通讯-手机数码频道-中文科技资讯...
  3. python实现列表的排序方法
  4. 太厉害了!专属于Java程序员的学习福音,经典好文
  5. 计算机主板性能,不同价位的主板性能有差别吗_主板评测-中关村在线
  6. android MediaPlayer + GLSurfaceView播放视频
  7. Wein2K入门操作(1)
  8. AOJ606 LOL系列之德玛短路
  9. 使用burp suite或fiddler进行越权测试的步骤
  10. linux shell until语句详解