ZOJ 3600 Taxi Fare(精度误差)

题意:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3600

思路:注意精度向上进位

#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int cas;
    scanf("%d",&cas);
    while(cas--)
        {
            int n,t;
            scanf("%d%d",&n,&t);
            float ansa,ansb;
            if(n<=3)
            {
                ansa=11;
                ansb=11;
            }
            else if(3<n&&n<=10)
            {
                ansa=(n-3)*2.0;
                ansb=(n-3)*2.5;
            }
            else
            {
                ansa=14+(n-10)*3.0;
                ansb=17.5+(n-10)*3.75;
            }
            float  ta,tb;

            ta=2.0/5;
            tb=2.5/4;
            ta=t*ta;
            tb=t*tb;

            ansa+=ta;
            ansb+=tb;
            int aa=(int)(ansa+0.5);//费用向上进位 
            int bb=(int)(ansb+0.5);
            printf("%d
",bb-aa);
        }
    return 0;
}

  

  

原文地址:https://www.cnblogs.com/sola1994/p/3926743.html