zoukankan      html  css  js  c++  java
  • [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)<<'
    ';
    23     }return 0;
    24 }
    
    
  • 相关阅读:
    vue-cli的使用
    修饰模式(Decorator结构型)C#简单例子
    c#继承中的函数调用
    c#桥接模式(bridge结构模式)
    c#浅谈反射内存的处理
    C#中的try catch finally
    C#微信公众号开发系列教程(接收事件推送与消息排重)
    用 C# 读取二进制文件
    c#语言-多线程中的锁系统(一)
    .NET程序内,访问私有或者保护成员的技巧
  • 原文地址:https://www.cnblogs.com/zjutlitao/p/3603423.html
Copyright © 2011-2022 走看看