Mincost

1031: Mincost

时间限制: 1 Sec   内存限制: 128 MB
提交: 303   解决: 88
[ 提交][ 状态][ 讨论版]

题目描述

The cost of taking a taxi in Hangzhou is not a constant for each kilometer you travel: the first 4 kilometers costs 10 yuan (yuan is the monetary unit in China), even if you don't finish it; the next 4 kilometers costs 2 yuan each and the price for the rest of the trip is 2.4 yuan per kilometer; the last part of the trip is regarded as 1 kilometer even if it's shorter. A traveller may reduce the cost by reseting the meter at the middle of the trip if used wisely. For example, if the trip is 16 kilometers, he should cut it into two parts with the same length, each half will cost 18 yuan, with an overall cost of 36, less than the original price of 37.2. Now, given the length of the trip, find the minimum cost.

输入

The input contains several cases, each has one positive integer in a seperate line, representing the length of the trip. All input data are less than 10000000. Proceed until a case with zero, which should be ignored.

输出

For each case, output the minimum cost, leave one digit after decimal point if NECESSARY.

样例输入

3
9
16
0

样例输出

10
20.4
36

提示

来源


#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    //freopen("input.txt","r",stdin)
    double ans;int f;
    while(~scanf("%d",&f)&&f)
    {
        ans=0;
        if(f>0&&f<4)ans=10;
        else if(f>=4&&f<=8)ans=2+2*f;
        else
        {
            int k=f%8;
            ans=18*(f-k)/8;
            if(k<5)
             ans+=k*2.4;
            else
                ans+=10+(k-4)*2;
        }
        printf("%g\n",ans);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值