【CodeForces - 864C】Bus (模拟,有坑)

题干:

A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys.

The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.

There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.

What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0.

Input

The first line contains four integers abfk (0 < f < a ≤ 106, 1 ≤ b ≤ 109, 1 ≤ k ≤ 104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.

Output

Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.

Examples

Input

6 9 2 4

Output

4

Input

6 10 2 4

Output

2

Input

6 5 4 3

Output

-1

Note

In the first example the bus needs to refuel during each journey.

In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.

In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.

题目大意:

   输入a,b,f,k。(数据范围如题干,其实这题数据范围还是蛮重要的,,不然我也不敢这么构造了)首先定义说从坐标0~a和a~0均算是一次行程。有一辆车满载是b升油,一升油可以跑一个单位长度。中间在下标为f这个固定的点有加油站,每次加满油。出发前加满油,问你跑完k次行程最少需要加多少次油。如果跑不下来,输出-1。

解题报告:

  这题代码量其实不大,,我把很多代码都花在了排除特殊情况上。。。

   思路很多,,可以直接模拟,,但是代码量很大,,我是把他撸成了一条直线,,然后就成了贪心加油站问题了。。。就很简单了,,,但是特殊情况第一次提交的时候忘了排除了,,,刚开始判断输出-1的条件写错了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll a,b,f,k,tot;
ll dis[MAX],cur;
int main()
{ll ans = 0;cin>>a>>b>>f>>k;if(k>2) {if(b < 2*f || b < 2*(a-f)) {puts("-1"); return 0 ;}}else if(k == 2){if(b < f || b < 2*(a-f)) {puts("-1"); return 0 ;}}else {if(b < f || b < (a-f)) {puts("-1"); return 0 ;}}if(k&1) {int all = k/2;cur = 0;for(int i = 1; i<=all; i++) {dis[++tot] = cur+f;dis[++tot] = cur+2*a-f;cur += 2*a;}dis[++tot] = cur+f;cur += a;
//		for(int i = 1; i<=tot; i++) printf("%lld\n",dis[i]);}else {int all = k/2;cur = 0;for(int i = 1; i<=all; i++) {dis[++tot] = cur+f;dis[++tot] = cur+2*a-f;cur += 2*a;}
//		for(int i = 1; i<=tot; i++) printf("%lld\n",dis[i]);}dis[tot+1] = 2*a+(ll)1e10;ll now = b,cnt = 0;for(int i = 1; i<=tot; i++) {if(now >= cur) break;if(dis[i] <= now && dis[i+1] > now) {now = dis[i] + b;cnt++;}}printf("%lld\n",cnt);return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441243.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

大量html乱码seo,HTTPS改造之后网页错位乱码,影响SEO和正常访问,应该这样改

有一些朋友可能不太知道https改造怎么做&#xff0c;就学着网站的步骤进行&#xff0c;实际操作过程中可能会遇到很多问题。比如说有的会出现网页错位、页面乱码、后台功能无法使用的情况。昨天我们就有一个客户他自己做了https改造&#xff0c;但是造成后台无法上传图片的情况…

【NOIP2013积木大赛,NOIP2018铺设道路】积木大赛(思维,贪心)

题干&#xff1a; 题目描述 春春幼儿园举办了一年一度的“积木大赛”。今年比赛的内容是搭建一座宽度为nn的大厦&#xff0c;大厦可以看成由n块宽度为1的积木组成&#xff0c;第i块积木的最终高度需要是h_ihi​。 在搭建开始之前&#xff0c;没有任何积木&#xff08;可以看…

微型计算机中最小的单位,微型计算机中最小的数据单位是

微型计算机中最小的数据单位是比特。微型计算机&#xff0c;是指由微处理器作为CPU的计算机。由大规模集成电路组成的、体积较小的电子计算机。由微处理机(核心)、存储片、输入和输出片、系统总线等组成。特点是体积小、灵活性大、价格便宜、使用方便。这类计算机的普遍特征就是…

【每日算法】【图论】【最小边覆盖 最小路径覆盖 最小顶点覆盖 最大独立集 最大团】

最小边覆盖 最大独立集 |V| - 最大匹配数 这个是在原图是二分图上进行的 最小路径覆盖和最小边覆盖不同&#xff0c;不要求给的图是二分图&#xff0c;而是要求是N x N的有向图&#xff0c;不能有环&#xff0c;然后根据原图构造二分图&#xff0c;构造方法是将点一分为二&am…

【51Nod - 1344】走格子 (思维)

题干&#xff1a; 有编号1-n的n个格子&#xff0c;机器人从1号格子顺序向后走&#xff0c;一直走到n号格子&#xff0c;并需要从n号格子走出去。机器人有一个初始能量&#xff0c;每个格子对应一个整数Aii&#xff0c;表示这个格子的能量值。如果Aii > 0&#xff0c;机器人…

计算机算法在生物信息学中的应用,计算机算法在生物信息学中的应用综述.doc...

计算机算法在生物信息学中的应用综述摘 要&#xff1a;在人类基因组计划的推动下&#xff0c;生物信息学得到了人们的广泛关注&#xff0c;并呈现出数量多、计算量大等鲜明特征&#xff0c;因此要求在生物信息学中采用计算机算法&#xff0c;以提高生物信息学处理问题的效率。以…

信息学竞赛计算机基础知识,信息学奥赛-计算机基础知识.doc

信息学奥赛-计算机基础知识TOC \o "1-3" \h \z \u HYPERLINK \l "_Toc303947525" 第一章 计算机基础知识 PAGEREF _Toc303947525 \h 2HYPERLINK \l "_Toc303947526" 第一节 数制及其转换 PAGEREF _Toc303947526 \h 2HYPERLINK \l "_Toc3039…

【51Nod - 1182】完美字符串(贪心,字符串)

题干&#xff1a; 约翰认为字符串的完美度等于它里面所有字母的完美度之和。每个字母的完美度可以由你来分配&#xff0c;不同字母的完美度不同&#xff0c;分别对应一个1-26之间的整数。 约翰不在乎字母大小写&#xff08;也就是说字母A和a的完美度相同&#xff09;。给定一…

【51Nod - 1133】不重叠的线段 (贪心)

题干&#xff1a; X轴上有N条线段&#xff0c;每条线段有1个起点S和终点E。最多能够选出多少条互不重叠的线段。&#xff08;注&#xff1a;起点或终点重叠&#xff0c;不算重叠&#xff09;。 例如&#xff1a;151523233636&#xff0c;可以选23233636&#xff0c;这2条线段…

xml html 转化为字符串,XSLT:将字符串解析为XML节点集(concret:将HTML-String转换为节点集)?...

我面临的问题是我在XML中有一个字符串的节点&#xff0c;代表HTML。 我需要削减该字符串&#xff0c;但是&#xff0c;当然&#xff0c;这可能导致在invalide HTML的标记(例如&#xff0c;如果我切字符串总是后30个字符我很容易失去闭元件等等)。 怎么办&#xff1f; 这似乎是非…

【51Nod - 1106 】质数检测 (水题,数论)

题干&#xff1a; 给出N个正整数&#xff0c;检测每个数是否为质数。如果是&#xff0c;输出"Yes"&#xff0c;否则输出"No"。 Input 第1行&#xff1a;一个数N&#xff0c;表示正整数的数量。(1 < N < 1000) 第2 - N 1行&#xff1a;每行1个数…

华中科技大学计算机系统结构,华中科技大学计算机系统结构复习题.pdf

Advanced Computer Architecture高级计算机系统结构 (复习题)-考试时间&#xff1a;1月20号下午根据曹强老师的写的&#xff0c;不知道会不会有错误&#xff0c;祝大家好成绩——by刘梦博By刘梦博Amdahl’s Law Fractionenhanced  ExTimenew  ExTimeold  1 Fract…

琴生不等式一般形式_001.二次函数、方程和不等式知识点

学法指导&#xff1a;本专题讲授不等式内容&#xff0c;这部分内容是学生的难点&#xff0c;为此有几点说明&#xff1a;1.把握好学习的难度。按教材内不等式部分展现的内容看&#xff0c;它很简单&#xff0c;但学过的知道&#xff0c;这部分内容很难&#xff0c;直白的讲&…

【51Nod - 1432】独木舟 (贪心,思维,好题)

题干&#xff1a; n个人&#xff0c;已知每个人体重。独木舟承重固定&#xff0c;每只独木舟最多坐两个人&#xff0c;可以坐一个人或者两个人。显然要求总重量不超过独木舟承重&#xff0c;假设每个人体重也不超过独木舟承重&#xff0c;问最少需要几只独木舟&#xff1f; …

计算机组成西电裘答案,西电计算机组成原理.ppt

西电计算机组成原理.ppt* * * * * * * * * * * * * * * * * * * * * * * * * * * * * 指令类型 指令的典型分类&#xff1a; 数据传送类 算术运算类 逻辑运算类 移位类 字符串操作类 数据转换类 输入/输出类 程序控制类 系统控制类 * 指令类型——数据传送类 完成源操作数与目的…

d3设置line长度_万物皆可Embedding之LINE算法解读

需要论文的朋友可以后台私信我获取前言上一篇文章给大家带来了Graph Embedding技术中的代表算法Deepwalk&#xff0c;今天给大家介绍graph embedding又一代表算法——LINE,LINE(large-scale information Network&#xff0c;大规模信息网络)致力于将大型的信息网络嵌入到低维的…

专转本计算机第一章试题,江苏专转本 计算机第一章自测题(含答案).doc

《江苏专转本 计算机第一章自测题(含答案).doc》由会员分享&#xff0c;提供在线免费全文阅读可下载&#xff0c;此文档格式为doc&#xff0c;更多相关《江苏专转本 计算机第一章自测题(含答案).doc》文档请在天天文库搜索。1、&#xfeff;第一章补充习题一、判断题&#xff1…

【HDU - 2012】素数判定(水题,数论,打表)

题干&#xff1a; 解题报告&#xff1a; AC代码1&#xff1a; #include<bits/stdc.h> #define MAX 10000//求MAX范围内的素数 using namespace std; long long su[MAX],cnt; bool isprime[MAX]; void prime() { cnt1; memset(isprime,1,sizeof(isprime)); isp…

【POJ - 3048】Max Factor (数论,打表,水题)

题干&#xff1a; To improve the organization of his farm, Farmer John labels each of his N (1 < N < 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better …

伺服电机停的时候会冲一下_造成伺服电机抖动的原因竟然是它!内附解决方法...

伺服电机(servo motor )是指在伺服系统中控制机械元件运转的发动机&#xff0c;是一种补助马达间接变速装置。它可使控制速度&#xff0c;位置精度非常准确&#xff0c;可以将电压信号转化为转矩和转速以驱动控制对象。伺服电机转子转速受输入信号控制&#xff0c;并能快速反应…