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 ...
随机推荐
- CentOS 7 安装Memcached服务
Memcached 简介 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站 ...
- mysql-5null值处理
值为null遇到的问题: 1.使用select对数据进行处理时,如果有格值为null,该命令会无法正常工作.如示例一 2.使用where限定条件时,null值不能处理.如示例二 -- 新建一张表,并填 ...
- while循环-for循环
while true: 无限循环语句 break跳出循环,当count=1000的时候结束循环 count是结束当前循环'''count = 0while True: print("coun ...
- pycharm -- 小技巧1 (显示文件的代码结构以及错误提示)
背景介绍 今天上午,在调用同事昨天给的算法程序时出了点问题,于是请同事来我这边一起调代码.大致场景描述如下: 我:B神,你昨天下班前给我的那个算法程序我这边调用的时候出现错误啦,请你过来看下呗. 同事 ...
- go语言数组与切片比较
一.数组 与其他大多数语言类似,Go语言的数组也是一个元素类型相同的定长的序列. (1)数组的创建. 数组有3种创建方式:[length]Type .[N]Type{value1, value2, . ...
- python manage.py runserver 0.0.0.0:8000
python manage.py runserver 这种命令行,可以在服务器端输入IP:8000直接访问 在 python manage.py runserver 127.0.01:8000 在服务 ...
- 无法定位程序输入点 Can't load package
---------------------------Toggle Form/Unit (F12): bcb.exe - 无法找到入口--------------------------- 无法定位程 ...
- Nginx 实现 IP+项目名 访问
参考: https://blog.csdn.net/csdn1152789046/article/details/51362735 修改前 项目放在Tomcat的webapps/ROOT/ 目录下面 ...
- 关于使用testng的retry问题
总体是利用TestNG里面的IRetryAnalyzer.TestListenerAdapter接口来实现相关问题 1.定义一个自己的retryanalyzer import org.testng.I ...
- JavaScript中call,apply,bind方法
why?call,apply,bind干什么的?为什么要学这个? 一般用来指定this的环境,在没有学之前,通常会有这些问题. var a = { user:"追梦子", fn:f ...