ZOJ2256 Mincost 2017-04-16 19:36 44人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- 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) ...
- 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 ...
- DateTime日期格式获取 分类: C# 2014-04-15 10:36 233人阅读 评论(0) 收藏
c#.net 获取时间年月日时分秒格式 //获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now. ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏
Happy Necklace Time Limit: ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- 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 ...
- 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 ...
- IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏
IP Address Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19125 Accepted: 11053 Desc ...
随机推荐
- HTML第三讲(选择符)
本次课程讲CSS中的选择符 1.基本选择符 基本选择符有三个 1.标记名选择符 所谓的标记名选择符就是直接在样式中使用标记名定义,譬如以下代码: (此种选择符的特点是所有相同的标记名可以同时定义不需要 ...
- WinForm各浏览器内核控件
WebKit.NET webkit-sharp CefSharp awesomium OpenWebKitSharp geckofx MozNet Web Component
- postman 前置 和 后置 处理器 用法
基本用法 赋予变量 var body="我是变量的值" ; -----给body赋值 postman.setEnvironmentVariable("sign&qu ...
- Educational Codeforces Round 37-G.List Of Integers题解
一.题目 二.题目链接 http://codeforces.com/contest/920/problem/G 三.题意 给定一个$t$,表示有t次查询.每次查询给定一个$x$, $p$, $k$,需 ...
- 常见报表的JS代码
1.合并单元格 这个表格在报表里面算是比较典型的 1.里面的表格的列标题现在是写死的,其实这些可以通过配置进行 2.至于如果表头要进行合并(这种需求比较少,也比较容易实现) 3.至于统计:最好在后台按 ...
- Solr中Facet用法和Group用法
Group分组划分结果,返回的是分组结果: Facet分组统计,侧重统计,返回的是分组后的数量: 一.Group用法: //组查询基础配置params.set(GroupParams.GROUP, & ...
- Pthreads n 体问题
▶ <并行程序设计导论>第六章中讨论了 n 体问题,分别使用了 MPI,Pthreads,OpenMP 来进行实现,这里是 Pthreads 的代码,分为基本算法和简化算法(引力计算量为基 ...
- Access空字符串和Null值
什么是空字符串和Null值: Microsoft Access可以区分两种类型的空值.因为在某些情况下,字段为空,可能是因为信息目前无法获得,或者字段不适用于某一特定的记录.例如,表中有一个“电话号码 ...
- matplotlib —— 添加文本信息(text)
[详细]http://hyry.dip.jp/tech/book/page/scipy/matplotlib_fast_plot.html http://blog.csdn.net/lanchunhu ...
- c++程序的多文件组织
当程序规模变大后,一个程序用多个文件组织,便于组织生产.这样,不必每次都重复对所有代码进行编译,而只需编译一次即可.把编译后所形成的目标文件保存起来,以后在需要时把它调出来直接与程序的目标文件相连接即 ...