1. 程式人生 > >Codeforces 534B - Covered Path

Codeforces 534B - Covered Path

col alt using out 速度 its cover include sync

534B - Covered Path

思路:貪心,每一秒取盡可能大速度。

畫張圖吧,不解釋了:

技術分享

代碼:

#include<bits/stdc++.h>
using namespace std; 
#define ll long long
int dp[105],dp1[105];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int v1,v2,t,d;
    cin>>v1>>v2>>t>>d;
    
    dp[1]=v1;
    
for(int i=2;i<=t;i++)dp[i]=dp[i-1]+d; dp1[t]=v2; for(int i=t-1;i>=1;i--)dp1[i]=dp1[i+1]+d; int ans=0; for(int i=1;i<=t;i++)ans+=min(dp[i],dp1[i]); cout<<ans<<endl; return 0; }

Codeforces 534B - Covered Path