codeforces 864C

2706 단어 모방하다
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 pointx = 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 pointx = 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 = 0is 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 pointx = 0.
Input
The first line contains four integers a, b, f, k (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

제목: 수축에 a점이 하나 있고 0시와 a점 사이에 f점이 주유소(휘발유는 매번 b까지 추가할 수 있음)가 있다. 자동차는 0에서 a까지 또는 a에서 0까지 한 번 여행을 계산한다. 자동차는 처음에 0시, 휘발유는 b로 k번의 여행 최소 주유 횟수를 구하고 k번의 여행을 만족시키지 못하면 출력한다.
사고방식: 점 사이의 거리를 수조로 바꾼다.
#include
#include
#include
using namespace std;
int a,b,f,k;
int dis[100005];
int main()
{
	scanf("%d%d%d%d",&a,&b,&f,&k);
	int curpos=0,curgas=b,curg=0;
	int ans=0;
	dis[0]=f;      //     ,0      
	for(int i=1;icurgas)      //            
		{
			curgas=b;
			ans++;
		}
		else if(i

좋은 웹페이지 즐겨찾기