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;
}



ZOJ2256 Mincost 2017-04-16 19:36 44人阅读 评论(0) 收藏的更多相关文章

  1. HDU1102&&POJ2421 Constructing Roads 2017-04-12 19:09 44人阅读 评论(0) 收藏

    Constructing Roads Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) ...

  2. ZOJ2482 IP Address 2017-04-18 23:11 44人阅读 评论(0) 收藏

    IP Address Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose you are reading byte streams fr ...

  3. DateTime日期格式获取 分类: C# 2014-04-15 10:36 233人阅读 评论(0) 收藏

    c#.net 获取时间年月日时分秒格式 //获取日期+时间 DateTime.Now.ToString();            // 2008-9-4 20:02:10 DateTime.Now. ...

  4. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  5. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  6. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  7. ZOJ2405 Specialized Four-Digit Numbers 2017-04-18 20:43 44人阅读 评论(0) 收藏

    Specialized Four-Digit Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB Find and list all f ...

  8. The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20304 ...

  9. IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19125   Accepted: 11053 Desc ...

随机推荐

  1. 显示等待WebDriverWait

    显示等待:WebDriverWait 等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常 WebDriverWait(driver, timeout, poll ...

  2. Keil for ARM与C++

    1. 如果你的程序中使用了C++全局变量,那么*不要*使用MicroLIB,否则Keil会说某某Symbol找不到 2. 不使用MicroLIB带来的一个问题是KEIL会使用semihosting S ...

  3. unittest框架出报告乱码的问题解决

    跟着上面的步骤修改好后,unittest断言写法要写成下面这样才能展示非乱码

  4. python调用R语言,关联规则可视化

    首先当然要配置r语言环境变量什么的 D:\R-3.5.1\bin\x64; D:\R-3.5.1\bin\x64\R.dll;D:\R-3.5.1;D:\ProgramData\Anaconda3\L ...

  5. javascript中原型,构造器,还有E5扩展的默认成员

    对象原型所具有的基本特征: 1.toString() 2.toLocaleString() 3.valueOf() 4.constructor() 5.propertyIsnumerable() 6. ...

  6. 认识Linux操作系统

    Linux系统是一个类似UNIX的操作系统 认识Linux的来世与今生 1.Linux系统的历史 Linux系统是一个类似UNIX的操作系统,Linux系统是UNIX在微机上的完整实现,它的标志是一个 ...

  7. 性能基准测试:KVM大战Xen

    编译自:http://major.io/2014/06/22/performance-benchmarks-kvm-vs-xen/作者: Major Hayden原创:LCTT https://lin ...

  8. 串口通信,帧与帧之间的时间间隔问题?9600波特率,帧将各在20ms以上

  9. c# 数据集调试工具插件

    DataSetSpySetup,调试期查看dataset数据集的记录内容, Debug DataSet

  10. (网页的缓存控制)HTML配置no-cache(备忘) “Cache-control”常见的取值

    HTML配置no-cache(备忘) No-cache配置 html表头如下 <meta http-equiv="Content-Type" content="te ...