描述
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 dkilometers and the waiting time is t minutes.
输入
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.
输出
For each test case, output the answer as an integer.
样例输入
4
2 0
5 2
7 3
11 4
样例输出
0
1
3
5
题目来源
http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4288
这道题唯一注意的一点就是题目告诉的等待价钱,修改前是等待5分钟2元,也就是每分钟0.4元,修改后是等待4分钟2.5元,也就是每分钟0.625元.
可能还有一个问题就是四舍五入,直接double转int只是取整,不会五入.那么我们可以给每个double加上0.5,这样double转int就成了四舍五入了.
#include <iostream>
using namespace std;
const double FT = 0.4;//改费前等待每分钟附加费
const double LT = 0.625;//改费后等待每分钟附加费
int main()
{
int n;
double fm,lm;
double d,t;
cin>>n;
while(n--)
{
fm = 0 ; lm = 0;
cin>>d>>t;
if(d>10)
{
fm += 3.0 * (d-10);
lm += 3.75 * (d-10);
d = 10;
}
if(d>3)
{
fm += 2.0 * (d-3);
lm += 2.5 * (d-3);
d = 3;
}
fm += FT*t;
lm += LT*t;
int ifm = fm + 0.5;//+0.5是为了四舍五入
int ilm = lm + 0.5;
//因为起步价相同都为11元所以没有算进去
cout<<ilm-ifm<<endl;
}
}