ZOJ 3600 Taxi Fare(模拟)

本文解析了ZOJ3600 Taxi Fare问题的模拟算法实现过程,通过分段讨论两种计费方式,并使用四舍五入处理结果。提供了完整的C++代码示例。

题目链接:ZOJ 3600 Taxi Fare

模拟。

比较两种计费方式的差值。分段讨论,比较简单。

四舍五入处理时候直接在double数上加0.5再向下取整就好了。

#include <iostream>

using namespace std;

double t, d, res1, res2;
int T;

int main()
{
    cin >> T;
    while(T--)
    {
        cin >> d >> t;
        res1 = res2 = 11;
        res1 += 2.5 * (t / 4);
        res2 += 2.0 * (t / 5);
        if(d > 3 && d <= 10)
        {
            res1 += (d - 3) * 2.5;
            res2 += (d - 3) * 2.0;
        }
        else if(d > 10)
        {
            res1 += ((7 * 2.5) + (d - 10) * 3.75);
            res2 += ((7 * 2.0) + (d - 10) * 3);
        }
        res1 = (int)(res1 + 0.5);
        res2 = (int)(res2 + 0.5);
        cout << (int)(res1 - res2) << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值