ZOJ 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


解题:

    个人觉得这道题说得非常不明不白,字面好像完全没说求两者的差值。

    还有一点可能困惑的是起步价和等待时间的关系,最后的结论是:3公里内起步价另加等待时间费用,其他按分段算就好。

    取整数,运算过程用浮点,最后加0.5取整就好。


代码:

#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n,d,t,cost1,cost2;
    cin>>n;
    while(n--)
    {
      cin>>d>>t;
      if(d<=3)
      {
        cost1=11;
        cost1+=t*2.0/5+0.5;
      }
      else
      {
        if(d<=10)
            cost1=10+1+(d-3)*2+t*2.0/5+0.5;
        else
            cost1=10+1+7*2+3*(d-10)+t*2.0/5+0.5;
      }
          if(d<=3)
          {
            cost2=11;
            cost2+=t*2.5/4+0.5;
          }
          else
          {
             if(d<=10)
               cost2=11+(d-3)*2.5+t*2.5/4+0.5;
             else
               cost2=11+7*2.5+(d-10)*3.75+t*2.5/4+0.5;
          }
      cout<<cost2-cost1<<endl;
    }
	return 0;
}


你可能感兴趣的:(ZOJ,省赛,最水题)