ZOJ3600-Taxi Fare

本文介绍了一种计算方法,用于对比杭州出租车新旧收费制度之间的费用差异。输入行驶距离及等待时间,通过算法计算出两种计费方式下乘客所需支付的金额,并得出两者之差。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


题意:求出两种计价方式的差值

解题思路:四舍五入处理时候直接在double数上加0.5再向下取整就好


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>

using namespace std;

int main()
{
    int T;
    double d,t,x1,x2;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf %lf",&d,&t);
        x1=x2=11;
        x1+=2.5*(t/4);
        x2+=2.0*(t/5);
        if(d>3&&d<=10)
        {
            x1+=(d-3)*2.5;
            x2+=(d-3)*2.0;
        }
        else if(d>10)
        {
            x1+=((7*2.5)+(d-10)*3.75);
            x2+=((7*2.0)+(d-10)*3);
        }
        x1=(int)(x1+0.5);
        x2=(int)(x2+0.5);
        printf("%d\n",abs((int)(x1-x2)));
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值