Main topic:
A car that is constant in speed every second ... The speed of the second to i+1 seconds does not change more than D. The initial speed is V1, the end speed is V2, after the time t, ask how far to go.
Analysis
I wanted to get into trouble at first. Various situations were discussed. It is found that the maximum value of each moment satisfies certain constraint relationship. Set at this time I, the last speed is P, then this time the speed should be Max (p+d,v2+ (t-i) *d), because to ensure that eventually will be able to return to V2. This allows you to get the maximum value for each moment and then add the sum.
1#include <cstdio>2#include <iostream>3 using namespacestd;4 intMain ()5 {6 intv1,v2,t,d;7 inta[10000];8 while(SCANF ("%d%d", &v1,&v2)! =EOF)9 {Tenscanf"%d%d",&t,&d); Onea[0]=v1; A intk=0, tem=v1; - for(intI=2; i<=t;i++) - { theTem=min (tem+d,v2+ (t-i) *d); -a[++k]=tem; - } - intsum=0; + for(intI=0; i<=k;i++) -sum+=A[i]; +printf"%d\n", sum); A } at return 0; -}
Codeforces Round #298 (Div. 2) B. Covered Path