zjuoj 3600 Taxi Fare

时间:2024-10-29 18:34:56

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3600

Taxi Fare


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Last September, Hangzhou raised the taxi fares.

The original flag-down fare in Hangzhou was 10 yuan, plusing 2 yuan per kilometer after the first 3km and 3 yuan per kilometer after 10km. The waiting fee was 2 yuan per five minutes. Passengers need to pay extra 1 yuan as the fuel surcharge.

According to new prices, the flag-down fare is 11 yuan, while passengers pay 2.5 yuan per kilometer after the first 3 kilometers, and 3.75 yuan per kilometer after 10km. The waiting fee is 2.5 yuan per four minutes.

The actual fare is rounded to the nearest yuan, and halfway cases are rounded up. How much more money does it cost to take a taxi if the distance is d kilometers and the waiting time is t minutes.

Input

There are multiple test cases. The first line of input is an integer T ≈ 10000 indicating the number of test cases.

Each test case contains two integers 1 ≤ d ≤ 1000 and 0 ≤ t ≤ 300.

Output

For each test case, output the answer as an integer.

Sample Input

4
2 0
5 2
7 3
11 4

Sample Output

0
1
3
5

Author: WU, Zejun
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest

分析:

题目要求第二种收费方式比第一种多多少钱,直接计算即可。

需要注意浮点数的操作。

AC代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<stack>
#include<map>
#include<cmath>
#include<string>
using namespace std;
double method1(double x1, double x2){
double cost = ;
if(x1 > 3.0) {
if(x1 <= 10.0){
cost += (x1-3.0)*2.0;
}
else{
cost += 7.0*2.0+(x1-10.0)*3.0;
}
}
cost += (2.0/5.0)*x2;
return cost;
}
double method2(double x1, double x2){
double cost = ;
if(x1 > 3.0){
if(x1 <= 10.0){
cost += (x1-3.0)*2.5;
}
else{
cost += 7.0*2.5+(x1-10.0)*3.75;
}
}
cost += (2.5/4.0)*x2;
return cost;
}
int main(){
int n;
double road, wait;
scanf("%d", &n);
while(n--){
scanf("%lf%lf", &road, &wait);
double ans1 = method1(road, wait);
double ans2 = method2(road, wait);
int sum1 = floor(ans1+0.5);
int sum2 = floor(ans2+0.5);
printf("%d\n", sum2-sum1);
}
return ;
}