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. equals方法和==的区别

    equals方法和==的区别   首先大家知道,String既可以作为一个对象来使用,又可以作为一个基本类型来使用.这里指的作为一个基本类型来使用只是指使用方法上的,比如String s = &quo ...

  2. SQL中禁用trigger

    SQL中禁用所有trigger   编写人:CC阿爸 2014-6-15 在日常SQL数据库的操作中,如何快速的禁用所有trigger? --禁用某个表上的所有触发器 ALTER  

  3. keepalive配置db层的ha的一些注意点

    具体db是那种都一样 db先做好replica,可以用自己带的,或者drbd的磁盘复制 db和keepalived必须在同一主机 keepalived里面的rs必须只有一个(否则,做不了主从,理论上会 ...

  4. 【记录】MVC4中使用SignalR

    前言 周末在偶尔翻阅微软官网的时候看到Getting Started with SignalR and MVC 4此篇文章,知道了signalr这个东西,貌似这个出来很长时间了,奈何自己一直没有发现, ...

  5. ps -ef 输出具体含义

    ps -ef 输出具体含义 UID        PID  PPID  C STIME TTY          TIME CMD 各相关信息的意义: UID 程序被该 UID 所拥有 PID 就是这 ...

  6. javascript 判断空数组

    javascript里判断空数组不能用 []==[] 这样来判断,因为数组也是个对象,普通对象通过指针指向的内存中的地址来做比较 所以 []==[]结果为false,因此判断数组是否为空 用 [].l ...

  7. 如何制作简单的 3D 打印模型

    Hi 大家好! 了解一个方兴未艾,但极为有趣的话题 — 3D 打印 . 为了帮助大家对3D打印有一个初步的感性认识,我在线制作了一款可用于3D打印的model, 大家可以先通过体验这个在线 model ...

  8. canvas绘制文本

    canvas绘制文本 属性和方法 font = value 设置字体 textAlign = value 设置字体对齐方式 start, end, left, right, center textBa ...

  9. pycharm中使用redis模块入门

    数据缓存系统:1:mongodb:是直接持久化,直接存储于硬盘的缓存系统2:redis: 半持久化,存储于内存和硬盘3:memcache:数据只能存储在内存里的缓存系统 redis是一个key-val ...

  10. ES6系列_4之扩展运算符和rest运算符

    运算符可以很好的为我们解决参数和对象数组未知情况下的编程,让我们的代码更健壮和简洁. 运算符有两种:对象扩展运算符与rest运算符. 1.对象扩展( spread)运算符(...) (1)解决参数个数 ...