日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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?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

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 (模拟,有坑)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。