[ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]

简介:


Description

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


题目大意:新旧2中出租车要价方案,问2次价格相差多少。注意每种价钱要用四舍五入!
解题思路:分段函数+每个价钱分别四舍五入相减。

复制代码
 1 #include<iostream>
 2 using namespace std;
 3 int first(int d,int t){
 4     double sum=11;
 5     sum+=2/5.0*t;
 6     if(d>3 && d<=10)sum+=2*(d-3);
 7     else if(d>10)sum+=(3*(d-10)+7*2);
 8     return (int)(sum+0.5);
 9 }
10 int second(int d,int t){
11     double sum=11;
12     sum+=2.5/4*t;
13     if(d>3 && d<=10)sum+=(d-3)*2.5;
14     else if(d>10)sum+=((d-10)*3.75+7*2.5);
15     return (int)(sum+0.5);
16 }
17 int main(){
18     int T;cin>>T;
19     while(T--){
20         int d,t;
21         cin>>d>>t;
22         cout<<second(d,t)-first(d,t)<<'\n';
23     }return 0;
24 }
复制代码


相关文章
|
1月前
|
存储 算法 索引
模拟算法题练习(二)(DNA序列修正、无尽的石头)
模拟算法题练习(二)(DNA序列修正、无尽的石头)
|
4月前
|
C语言
c语言编程练习题:7-23 分段计算居民水费
c语言编程练习题:7-23 分段计算居民水费
48 0
|
8月前
|
算法 C语言
基于雨流计数法的源-荷-储双层协同优化配置研究(Matlab代码实现)
基于雨流计数法的源-荷-储双层协同优化配置研究(Matlab代码实现)
|
12月前
|
机器学习/深度学习 存储 人工智能
啊哈 算法读书笔记 第 1 章 一大波数正在靠近——排序
首先出场的是我们的主人公小哼,上面这个可爱的娃就是啦。期末考试完了老师要将同 学们的分数按照从高到低排序。小哼的班上只有 5 个同学,这 5 个同学分别考了 5 分、 3 分、 5 分、 2 分和 8 分,哎考得真是惨不忍睹(满分是 10 分)。接下来将分数进行从大到小排序, 排序后是 8 5 5 3 2 。你有没有什么好方法编写一段程序,让计算机随机读入 5 个数然后将这 5 个数从大到小输出?
69 0
|
决策智能
运筹优化学习02:Lingo求解带容量约束的车辆路径问题(CVRP)(上)
运筹优化学习02:Lingo求解带容量约束的车辆路径问题(CVRP)
运筹优化学习02:Lingo求解带容量约束的车辆路径问题(CVRP)(上)
|
决策智能
运筹优化学习02:Lingo求解带容量约束的车辆路径问题(CVRP)(下)
运筹优化学习02:Lingo求解带容量约束的车辆路径问题(CVRP)
运筹优化学习02:Lingo求解带容量约束的车辆路径问题(CVRP)(下)
|
数据可视化
信号处理系统综合设计-求解器函数的设计(连续和离散时间系统)
信号处理系统综合设计-求解器函数的设计(连续和离散时间系统)
191 0
信号处理系统综合设计-求解器函数的设计(连续和离散时间系统)
|
机器学习/深度学习 算法
【计算理论】计算理论总结 ( 图灵机设计示例 ) ★★
【计算理论】计算理论总结 ( 图灵机设计示例 ) ★★
298 0
|
机器学习/深度学习 资源调度 算法
【计算理论】计算理论总结 ( 图灵机设计 ) ★★
【计算理论】计算理论总结 ( 图灵机设计 ) ★★
318 0
【计算理论】计算理论总结 ( 图灵机设计 ) ★★

热门文章

最新文章