zoukankan      html  css  js  c++  java
  • The 9th Zhejiang Provincial Collegiate Programming Contest->Problem A:A

    Problem A: 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
    题意:旧方式:起步价10元,大于三公里2元/公里,大于十公里的2.5元/公里,等待费2元/5min,最后加1元给司机做额外汽油费。新方式:起步价11元,大于三公里2.5元/公里,大于十公里的3.75元/公里,等待费2.5元/4min。比较两种收费方式,算出相同里程的差价。
    主要是四舍五入的问题。。。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 double round(double val) {
     4     return (val> 0.0) ? floor(val+ 0.5) : ceil(val- 0.5);
     5 }
     6 int main() {
     7     int T;
     8     cin>>T;
     9     while(T--) {
    10         double d,t;
    11         double s1=11,s2=11;
    12         cin>>d>>t;
    13         s1+=2*t/5;
    14         s2+=2.5*t/4;
    15         if(d>3&&d<=10) {
    16             s1+=2*(d-3);
    17             s2+=2.5*(d-3);
    18         } else if(d>10) {
    19             s1+=2*7+3*(d-10);
    20             s2+=2.5*7+3.75*(d-10);
    21         }
    22         double r=round(s2)-round(s1);
    23         //double r=(int)(s2+0.5)-(int)(s1+0.5);
    24         printf("%.0f ",r);
    25     }
    26     return 0;

    27 } 


    我会一直在
  • 相关阅读:
    Unity NGUI 2D场景添加按钮
    EaseType缓动函数
    在没有网络的情况下用安卓手机和数据线让台式电脑上网
    面向对象编程
    static与C#中的static
    C#基础
    iSensor APP 之 摄像头调试 OV5642
    iSensor APP 之 摄像头调试 OV9655
    USB3.0之高速视频传输测试 双目相机(mt9p031、mt9m001)带宽高达300M测试 配合isensor测试 500万像素15fps
    模拟摄像头解码模块最新测试 TVP5150模块 FPGA+SDRAM+TVP5150+VGA 实现PAL AV输入 VGA视频输出
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5402472.html
Copyright © 2011-2022 走看看