A. Sasha and His Trip

版权声明:转载请注明出处,谢谢。 https://blog.csdn.net/Mercury_Lc/article/details/87620635

Codeforces Round #539 (Div. 2)

&:刷水题找信心系列。

题意:开车从1出发到n,油箱体积V,1-n在一条直线上,相邻相距是1,i 个城市的油价是 i 元一升,一升油可以走 1 个单位,问消耗最小钱到达n。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005 ;
const int N = 26 ;

int main()
{
    int n,v;
    scanf("%d %d", &n, &v);
    if(v + 1 >= n)  // 如果油箱体积足够大,就可以直接到达
    {
        v = min(v,n - 1);
        printf("%d\n",v);
        return 0;
    }
    int pos = 1;
    int ans = v;
    while(pos + 1 != n) // 否则,每次到一个新城市,就把油补满
    {
        if(v >= n - pos) {  // 判断不补满是否可以到
            break;
        }
        pos ++;
        ans += pos;
    }
    printf("%d\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/87620635
今日推荐