1031: Mincost

2016-12-11 19:04:41来源:CSDN作者:Z374012581人点击

第七城市

题目描述

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>int main(){    long n,m,k;    while(scanf("%ld",&n)!=EOF && n!=0)    {        k=n%8;        m=n/8;        if(n<=8) if(n<=4) printf("10/n");                 else printf("%ld/n",2*n+2);        else if(k<5)                  if((2*n-m)%5==0) printf("%ld/n",(n/4)*9);                 else printf("%.1f/n",(float)n*2.4-1.2*(float)m);             else printf("%ld/n",2*m+2*n+2);    }    return 0;}
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台