ZOJ2256-Mincost
来源:互联网 发布:淘宝买家秀的福利网站 编辑:程序博客网 时间:2024/06/06 01:27
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
Author: PAN, Minghao
Source: ZOJ Monthly, November 2004
题思:某市出租车计价按一下标准: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 longconst 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
- ZOJ2256-Mincost
- Mincost
- Mincost
- 1031: Mincost
- zoj2256//计程车 最小花费 5为分界…
- ZOJ 2256 Mincost
- find the mincost route
- find the mincost route
- zoj 2256 Mincost
- hdu1599find the mincost route
- OJ 21之Mincost(
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- ZOJ 2256Mincost
- find the mincost rout
- 仿arrow.io之人物控制
- VM+Lamp环境搭建
- MYSQL常用命令
- SQL删除重复数据方法
- Angularjs开发一些经验总结
- ZOJ2256-Mincost
- Excel拼装Sql语句将数据批量导入数据库
- 绝对定位的盒子如何实现水平垂直居中
- 如何为你的代码选择一个开源协议
- 在Jupyter Notebook 中使用 Tensorflow
- Android设置默认取消获得焦点或显示软键盘
- Mybatis连接MySQL或者ORALE 12C 入门实例。
- 使用openssl进行证书格式转换
- 侧滑Drawerlayout