Test instructions: gives you the initial speed and end speed, as well as the running time and acceleration maximum, asking you to ask for the distance to run.
Problem-solving ideas: With the smaller that speed positive to add, the larger the speed of the reverse plus, take each time the min add is the request.
Problem Solving Code:
1 //File name:b.cpp2 //Author:darkdream3 //Created time:2015 April 13 Monday 00:13 25 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - - using namespacestd; - intV1,v2; - intt,d; in inta[ the]; - intb[ the]; to intMain () { +scanf"%d%d",&v1,&v2); -scanf"%d%d",&t,&d); the if(V2 <v1) * swap (V1,V2); $a[1] =v1;Panax Notoginseng intsum = a[1]; - for(inti =2; I <= T;i + +) the { +A[i] = a[i-1] +D; ASum + =A[i]; the } + -B[T] =v2; $Sum-= (A[t]-b[t]); $ for(inti = t1; I >=1; I--) - { -B[i] = b[i+1]+D; the if(B[i] >A[i]) - Break;Wuyi //printf ("%d%d\n", A[i],b[i]); the -Sum-= (a[i]-b[i]); Wu } -printf"%d\n", sum); About return 0; $}View Code
Codeforces 534B Covered Path Greedy