Mincost

2024-09-02 18:48
文章标签 mincost

本文主要是介绍Mincost,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1031: Mincost

时间限制: 1 Sec   内存限制: 128 MB
提交: 303   解决: 88
[ 提交][ 状态][ 讨论版]

题目描述

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.

输入

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.

输出

For each case, output the minimum cost, leave one digit after decimal point if NECESSARY.

样例输入

3
9
16
0

样例输出

10
20.4
36

提示

来源

ZOJ Monthly, November 2004


#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{//freopen("input.txt","r",stdin)double ans;int f;while(~scanf("%d",&f)&&f){ans=0;if(f>0&&f<4)ans=10;else if(f>=4&&f<=8)ans=2+2*f;else{int k=f%8;ans=18*(f-k)/8;if(k<5)ans+=k*2.4;elseans+=10+(k-4)*2;}printf("%g\n",ans);}return 0;
}


这篇关于Mincost的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1130770

相关文章

hdu1599 find the mincost route

find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1444    Accepted Submission(s): 590 Problem Description 杭州有N个景

hdu1599find the mincost route (floyd算法,相对模板而言时间优化了一半)

Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个景区。现在8600需要你帮他找一条这样的路线,并且花费越少越好。 Input

hdu1599find the mincost route

题目大意:     在一个图里面找至少有三条边的无向环的最短路径。如果不存在有三条边以上的无向环则输出"It's impossible.". 解题思路:     带环了,所以就采用floyd算法吧,因为其它几种都是适用于单源的。     先上图;             至少三条边以上,按照一般思路的话,既然是最短路径,那我们肯定是边越少越好。但是从上图就可以看出,这个观点是显然不成立

hdu 1599 find the mincost route(floyd 最小环)

题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18884 find the mincost route Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status Descri

HDU 1599 find the mincost route (Floyd 最小环)

find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2802    Accepted Submission(s): 1116 Problem Description 杭州有N

find the mincost route

  find the mincost route Crawling in process... Crawling failed      Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u        Description 杭州有N个景区,景区之间有一些双向的路

hdu 1599 find the mincost route 无向图的最小环 求从一个点遍历所有节点以后回到原点的最短

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴! 在写题解之前给自己打一下广告哈~。。抱歉了,希望大家多多支持我在CSDN的视频课程,地址如下: http://edu.csdn.net/course/detail/209 题目: find