码迷,mamicode.com
首页 > 其他好文 > 详细

ural 1113,jeep problem

时间:2016-09-23 01:23:20      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1113

网上的解答铺天盖地。我硬是花了两天才懂了点。

wiki上的解释:https://en.wikipedia.org/wiki/Jeep_problem

 

解答:每个点的油量是500,500*2,500*3... ...

每次的距离是500,500/3,500/5,... ...,500/2n-1;

#include <bits/stdc++.h>
using namespace std;

int main()
{
    double dist, tank;
    scanf("%lf%lf", &dist, &tank);
    double now = dist, cost = 0, pre;
    int k = 1;
    while( (pre = now - tank / (2*k-1)) > 0){
        cost += tank;
        now = pre;
        k++;
    }
    cost += now * (2*k-1);
    printf("%.0f\n", ceil(cost));
    return 0;
}

 

ural 1113,jeep problem

标签:

原文地址:http://www.cnblogs.com/TreeDream/p/5898407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!