H - Taxi
来源:互联网 发布:平板 知乎 编辑:程序博客网 时间:2024/04/28 05:38
Description
Petr likes going by taxi. For him, it is not only the pleasure of a fast and comfortable ride, but also the opportunity to bargain with the driver over the fare. The bargaining between Petr and taxi drivers always follows the same scheme:
— To the airport! I pay 150 roubles.
— No, I won't take you for 150. Let's go for 1000.
— Are you crazy? I haven't got that much on me! Ok, let it be 200.
— Are you laughing? I agree to 900.
— Well, I'll give 250.
— Guy, do you know how much gas is? Pay 800 and off we go!
…
Such a dialog continues until they agree on the fare. Petr always increases his amount by the same number, and the taxi driver decreases it in the same way. The driver would not ask a sum that is less than that offered by Petr. In this case, he will agree with Petr's offer. Petr will act similarly.
— To the airport! I pay 150 roubles.
— No, I won't take you for 150. Let's go for 1000.
— Are you crazy? I haven't got that much on me! Ok, let it be 200.
— Are you laughing? I agree to 900.
— Well, I'll give 250.
— Guy, do you know how much gas is? Pay 800 and off we go!
…
Such a dialog continues until they agree on the fare. Petr always increases his amount by the same number, and the taxi driver decreases it in the same way. The driver would not ask a sum that is less than that offered by Petr. In this case, he will agree with Petr's offer. Petr will act similarly.
Input
The single input line contains four integer numbers: the initial Petr's offera, Petr's raise to his offerb, the initial fare required by the driverc, and the driver's reduction of his fared; 1 ≤ a,b, c, d ≤ 10000 .
Output
Output the amount of money that Petr will pay for the ride.
Sample Input
150 50 1000 100
450
#include<iostream>using namespace std;int main(){int a,b,c,d,ans=0;cin>>a>>b>>c>>d;if(a>=c) cout<<a<<endl;else {for(int i=0;;i++){if(a+b*i>=c-d*i){ ans=min(a+b*i,c-d*(i-1));break;}}cout<<ans<<endl;}return 0;}
0 0
- H - Taxi
- Taxi
- Taxi
- 讨厌taxi
- B. Taxi
- Taxi Fare
- Lesson29 Taxi!
- Coderforces Taxi
- Taxi Fare
- Taxi 3 eXtreme Rush
- Taxi Cab Scheme
- hdu1350.Taxi Cab Scheme
- POJ2060 Taxi Cab Scheme
- zoj 3600 Taxi Fare
- poj2060 - Taxi Cab Scheme
- CF - 158B - Taxi
- poj2060 Taxi Cab Scheme
- CodeForces 158B taxi
- 2016年计算机二级《C语言》基础练习题及答案
- Swift - View Transition
- coderforces342B. War of the Corporations【strstr】
- html js的主要用途
- 用js添加一个div
- H - Taxi
- coderforces342C. K-special Tables
- POJ1046 Color Me Less(水)
- js增加标签属性
- Objective-C Runtime系统
- [LeetCode]204. Count Primes
- EL表达式中的 javax.el.PropertyNotFoundException 分析
- Codeforces Round #342 (Div. 2)
- spymemcached和spring的整合