题干:

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 ;}

【CodeForces - 864C】Bus (模拟,有坑)相关推荐

  1. CodeForces 991E Bus Number DFS+ 组合数

    CodeForces 991E Bus Number DFS+ 组合数 题目大意:给定一个数字,数字里出现的每一个数,都至少要用一个,问能组成多少个新数,不加前导零. input: 2028 outp ...

  2. 【模拟】Codeforces 711A Bus to Udayland

    题目链接: http://codeforces.com/problemset/problem/711/A 题目大意: N个字符串,每个字符串5位,找到第一个出现两个OO的并改成++输出YES和改后字符 ...

  3. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...

  4. CodeForces - 1491E Fib-tree(模拟)

    题目链接:点击查看 题目大意:给出一棵树,问是否为斐波那契树.斐波那契树的定义是,树的大小为斐波那契数列的其中一项,且可以通过删除掉一条边使其拆分的两个子树也为斐波那契树 题目分析:需要观察到,大小为 ...

  5. VUE非父子组件通信Bus——公交车踩坑笔记

    抛开父子组件的通讯,对于非父子组件通信,简单的数据交互,使用Bus是非常不错的. 遇到的坑有两个. 1.两个组件的信息交互代码写在哪个生命周期函数中,如果只是点击组件A标签触发函数,然后向界面B传递参 ...

  6. 【PAT乙级】1014 福尔摩斯的约会 (20 分)【模拟 / 很坑】

    之前小号写过: https://blog.csdn.net/bettle_king/article/details/116546412 这里就直接复制过来了 https://pintia.cn/pro ...

  7. Codeforces 67A【模拟】

    题意: 给一个字符串代表相邻学生的比较,L代表左边多,R表示右边多,=表示左右相等. 保证每个人拿糖>=1,在分糖最少的情况下,输出每个学生所分得的糖. 思路: 模拟一下,第一个人一开始拿1个, ...

  8. CodeForces - 786C——二分+模拟?

    [题目描述] Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. ...

  9. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个"VK"子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试 ...

最新文章

  1. RESTful API -备
  2. 第三届山西省赛1004 一道大水题(scanf)
  3. 网络推广专员如何稳定搜索引擎首页排名全力以赴致力于网络推广
  4. jQuery1.9+中删除了live以后的替代方法
  5. aliyun服务器安装git,g++
  6. 【转】编译DCMTK
  7. python windows窗口置顶_想用Python编程却不知如何下手?一篇搞定编程准备工作
  8. poj 1094 Sorting It All Out(拓扑排序)
  9. ios 简单的计时器游戏 NSUserDefaults NSDate NSTimer
  10. python怎么读excelsheet_python怎么读写excel文件
  11. FreeSpan 和 PrefixSpan 算法学习
  12. 投入产出比增长2倍以上!银泰抛弃传统数据库转投阿里云PolarDB
  13. matlab 自带定积分,Matlab怎么计算定积分,划重点了
  14. Qt 基于Google引擎的拼音输入法
  15. 遥感图像计算机自动分类原理,遥感原理与应用_第5章_2遥感影像解译-遥感影像计算机自动分类讲义.ppt...
  16. ZN-17A机器人光机电一体化分拣实训系统
  17. 百度云apkg手机文件怎么打开_ipad上用百度云和notability学习时的各种七七八八
  18. 【CS231n】斯坦福大学李飞飞视觉识别课程笔记(六):线性分类笔记(上)
  19. qt linux不能读写u盘文件,Qt读取U盘文件内容
  20. U盘产生快捷方式病毒

热门文章

  1. 快速了解c#中的索引器
  2. HDU-5050 java大数
  3. python输出运行时间表_Python编程第十二课 了解程序运行的时间
  4. 用栈解决四则运算问题
  5. java链式调用空指针_java 链式调用
  6. 按群计数10以内_【乐玩乐学】有趣的计数活动
  7. matlab将数据输出到excel中,matlab将数据保存为excel表格-怎样将MATLAB中的数据输出到excel中...
  8. 14.6 Spring MVC 测试框架(翻译)
  9. 蓝图中实现人物移动1
  10. UE4中的字符串转换