The operating hours of a taxi company in a certain area are from 7:00 in the morning to 23:00. Their fare calculation method is as follows:
- Within the first 2 kilometers of the journey, the fare is $20. For each additional kilometer after the initial 2 kilometers, an additional $5 is charged.
- For every 2 minutes of waiting time, an additional $5 is charged.
- If the taxi ride spans from 6:00 PM to 11:00 PM, the additional fare for each time is as follows:
Time | Additional Fee |
---|---|
18:00 ~ 19:00 | $185 |
19:00 ~ 20:00 | $195 |
20:00 ~ 21:00 | $205 |
21:00 ~ 22:00 | $215 |
22:00 ~ 23:00 | $225 |
Given the "total kilometers traveled, vehicle delay time, passenger boarding time, and disembarking time", please help calculate the total fare for the ride.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The input consists of a single line containing four integers , representing the total kilometers traveled, vehicle delay time (in minutes) , the time the passenger got in, and the time the passenger got out (in hours). | Please output the total fare for the ride. |
1 1 7 8 | 20 |
1 2 12 13 | 25 |
2 1000 7 17 | 2520 |
20 60 13 15 | 260 |
150 36 17 18 | 850 |
150 36 17 19 | 1035 |
1000 1000 20 23 | 8155 |
Thought Process
預設答案為 20,將 K -= 2 後如果 K > 0 就將答案 += K * 5,之後再將答案 += W / 2 * 5。
宣告一個 Map<int, int>,Key 值存夜間時間的「開始」,Value 存對應的價錢。跑一個 For迴圈 從 S 到 E-1,將答案 += Map[目前跑到的小時]。
Sample Code-ZeroJudge H659: Taxi
#include <iostream>
#include <map>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int K, W, S, E, ans = 20;
cin >> K >> W >> S >> E;
K -= 2;
if (K > 0) ans += K * 5;
ans += W / 2 * 5;
map<int, int>MAP;
MAP[18] = 185;
MAP[19] = 195;
MAP[20] = 205;
MAP[21] = 215;
MAP[22] = 225;
for (int i = S; i<E; i++) {
ans += MAP[i];
}
cout << ans << "\n";
}
//ZeroJudge H659
//Dr. SeanXD