C. Bus
time limit per test:

2 seconds

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

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.

题目链接:http://codeforces.com/contest/864/problem/C

题意:有一条长度为a的道路,在距离起点k的地方有一个加油站,每次加油可以把有加满,现在有一辆容量为b的车没走一单位距离耗费1单位的有,现在要在这条路上开k趟,去是一趟,回来也是一趟,问最少需要加几次油。

思路:是否需要在本加油站加油,是看车能否到达下一个加油站,如果能,本加油站不加油;如果不能,本加油站需要加油。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define bug(x) cout<<"bug"<<X<<endl;
#define PI acos(-1.0)
#define eps 1e-8
typedef long long ll;
typedef pair<int,int > P;
int main()
{
ll a,b,f;
int k;
scanf("%lld%lld%lld%d",&a,&b,&f,&k);
int ans=;
ll sum=b;
for(int i=; i<=k; i++)
{
if(i%) sum-=f;
else sum-=a-f;
if(sum<) return *printf("-1\n");
if(i<k)
{
if(i%==&&sum-*(a-f)<) sum=b,ans++;
else if(i%==&&sum-*f<) sum=b,ans++;
}
else
{
if(i%==&&sum-(a-f)<) sum=b,ans++;
else if(i%==&&sum-f<) sum=b,ans++;
}
if(i%) sum-=a-f;
else sum-=f;
if(sum<) return *printf("-1\n");
}
printf("%d\n",ans);
return ;
}

Codeforces Round #436 (Div. 2)C. Bus 模拟的更多相关文章

  1. Codeforces Round #436 (Div. 2) C. Bus

    http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a ...

  2. Codeforces Round #436 (Div. 2)【A、B、C、D、E】

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  3. Codeforces Round #436 (Div. 2)D. Make a Permutation! 模拟

    D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...

  4. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  7. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  8. Codeforces Round #369 (Div. 2) A. Bus to Udayland 水题

    A. Bus to Udayland 题目连接: http://www.codeforces.com/contest/711/problem/A Description ZS the Coder an ...

  9. Codeforces Round #484 (Div. 2) B. Bus of Characters(STL+贪心)982B

    原博主:https://blog.csdn.net/amovement/article/details/80358962 B. Bus of Characters time limit per tes ...

随机推荐

  1. 在宿主机查看docker使用cpu、内存、网络、io情况

    命令: docker stats [OPTIONS] [CONTAINER...] 显示所有: docker stats -a

  2. 【java】static的应用场景

    定义静态原则: 什么时候定义静态变量:对象中出现共享数据时,该数据被static所修饰.如国家 什么时候定义静态方法:当功能内部没有访问到非静态数据时,该方法可以定义成静态的 工具类的例子: /** ...

  3. FPGA 主时钟约束---primary clocks

    FPGA 主时钟约束---primary clocks 个人的理解,FPGA做时钟约束的主要目的是给布局布线过程一个指导意义. 注:周期的参数值为ns waveform 里面的第一个参数为波形第一个上 ...

  4. ORACLE的impdp和expdp命令

    使用EXPDP和IMPDP时应该注意的事项: EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用. EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用, ...

  5. Properties类学习笔记

    1.Properties是一个hashTable子类,但它只装String类型的值2.一个Properties集中有一个子Properties集为它的默认属性集,如果在Properties中找不到相关 ...

  6. HTTP请求中 request payload 和 formData 区别?

    原文地址: http://www.cnblogs.com/tugenhua0707/p/8975615.html FormData和Payload是浏览器传输给接口的两种格式,这两种方式浏览器是通过C ...

  7. Java内存列表

    当jvm运行起来的时候,它会向系统申请一片内存区,并将这块内存分出一部分存储程序创建的对象,传递给方法的参数,返回值,局部变量等等,我们将这块内存称之为“运行时数据区”. 初学的时候把Java内存分为 ...

  8. SQLServer数据库镜像配置

    目录 一.目标...2 二.前提条件.限制和建议...2 三.设置概述...2 四.安装Sql Server 2008 enterprise X64.3 4.1.安装.NET3.5.3 4.2.安装时 ...

  9. win7 80端口被iis占用

    下载iis管理器,打开,关闭80端口占用

  10. JVM-即时编译JIT

    编译简介 在谈到JIT前,还是需要对编译过程有一些简单的了解. 在编译原理中,把源代码翻译成机器指令,一般要经过以下几个重要步骤: 什么是JIT1.动态编译(dynamic compilation)指 ...