ZOJ2256 Mincost
来源:互联网 发布:角色动画软件 编辑:程序博客网 时间:2024/05/16 18:13
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 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
- h5盒子模型
- 注解:从一个namespace跳转到另外一个namespace,Struts2
- SAP HANA查看某一用户最后登录时间及无效连接次数
- Request processing failed; nested exception is java.lang.NullPointerException
- vim配置文件 好用的列表
- ZOJ2256 Mincost
- Git安装文档
- 创建并运行第一个 XPages 应用程序
- 自考过后
- 计算机网络原理--考点
- CSDN日报20170416 ——《为什么程序员话少钱多死得早?》
- 动态规划 01题
- 阿里巴巴和n个大盗
- leetcode62. Unique Paths