题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离。
析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推。
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
vector<int> ans;
int a[1005];
int main(){
    int d, v1, v2, t;
    scanf("%d %d %d %d", &v1, &v2, &t, &d);
    int ans = 0;
    for(int i = 0; i < t; ++i)
        a[i] = i * d + v2;
    for(int i = 0; i < t; ++i){
        if(v1 + d * i > a[t-1-i]){
            ans += a[t-1-i];
        }
        else {
            ans += v1 + d * i;
        }
    }
    cout << ans << endl;
    return 0;
}
                
            
        
浙公网安备 33010602011771号