ZOJ2256 Mincost

Mincost

Time Limit: 2 Seconds       Memory Limit: 65536 KB

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.


Input

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.


Output

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


Sample Input

3
9
16
0


Sample Output

10
20.4
36



题目的意思是某市出租车计价按一下标准:4公里以内受10元,4~8每公里收2元,8公里以外每公里2.4元。现给出一段距离,中途可以下车,问最少要花多少钱?

通过计算我们可以很明显发现坐8公里平均价格最小,所以我们把距离尽可能分成8公里,多出来的部分算一下按8公里以外计价和重新乘那个便宜取哪个

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>

using namespace std;

#define LL long long
const int INF=0x3f3f3f3f;

int main()
{
 int n;
 while(~scanf("%d",&n)&&n)
 {
     if(n<4)
     {
         printf("10\n");
     }
     else if(n<=8)
     {
         printf("%d\n",10+2*(n-4));
     }
     else
     {
         int cnt=n/8;
         int x=n%8;
         if(x==0)
         {
             printf("%d\n",18*cnt);
         }
         else{
            double ad1=2.4*x;
            double ad2=10;
            if(x>4)
                ad2+=2*(x-4);
            double ans=cnt*18+min(ad1,ad2);
            if((int)ans==ans)
                printf("%.0f\n",ans);
            else
                printf("%.1f\n",ans);


         }
     }
 }
    return 0;
}






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值