Codeforces 1113A. Sasha and His Trip 题解

Posted withhope

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 1113A. Sasha and His Trip 题解相关的知识,希望对你有一定的参考价值。

原题链接:Codeforces 1113A. Sasha and His Trip
题目大意:你有一个油箱容积为(V)的车,每从第(i)个城市到第(i+1)个城市需要耗费一个单位的油,在第(i)个城市加油为(i)元每个单位,问从(1)号城市到(n)号城市最少花费。
题解:很明显的一个贪心,毕竟我们尽量早加油,因为费用便宜,所以,就直接给代码了:

#include <cstdio>
int mn(int a,int b){
    return a<b?a:b;
}
int mx(int a,int b){
    return a>b?a:b;
}
int main(){
    int n,v;
    scanf("%d%d",&n,&v);
    if(v>n-1){
        v=n-1;
    }
    int ans=0;
    int now=0;
    for(int i=1;i<n;i++){
        if(now<n-i){
            ans+=(v-now)*i;
            now=v;
        }
        now--;
    }
    printf("%d
",ans);
    return 0;
}


以上是关于Codeforces 1113A. Sasha and His Trip 题解的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 931F Teodor is not a liar!

Codeforces Round #539 (Div. 2) C Sasha and a Bit of Relax

Codeforces Round #425 (Div.2)

CodeForces 1109F. Sasha and Algorithm of Silence's Sounds

codeforces 718 C&DC. Sasha and Array&D. Andrew and Chemistry

CodeForces 718C Sasha and Array