zjuoj 3600 Taxi Fare

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代码:

 

 1 #include<cstdio>

 2 #include<algorithm>

 3 #include<cstring>

 4 #include<queue>

 5 #include<iostream>

 6 #include<stack>

 7 #include<map>

 8 #include<cmath>

 9 #include<string>

10 using namespace std;

11 double method1(double x1, double x2){

12     double cost = 11;

13     if(x1 > 3.0) {

14         if(x1 <= 10.0){

15             cost += (x1-3.0)*2.0;

16         }

17         else{

18             cost += 7.0*2.0+(x1-10.0)*3.0;

19         }

20     }

21     cost += (2.0/5.0)*x2;

22     return cost;

23 }

24 double method2(double x1, double x2){

25     double cost = 11;

26     if(x1 > 3.0){

27         if(x1 <= 10.0){

28             cost += (x1-3.0)*2.5;

29         }

30         else{

31             cost += 7.0*2.5+(x1-10.0)*3.75;

32         }

33     }

34     cost += (2.5/4.0)*x2;

35     return cost;

36 } 

37 int main(){

38     int n;

39     double road, wait;

40     scanf("%d", &n);

41     while(n--){

42         scanf("%lf%lf", &road, &wait);

43         double ans1 = method1(road, wait);

44         double ans2 = method2(road, wait);

45         int sum1 = floor(ans1+0.5);

46         int sum2 = floor(ans2+0.5);

47         printf("%d\n", sum2-sum1);

48     }

49     return 0;

50 }
View Code

 

你可能感兴趣的:(360)