Codeforces 534B Covered Path Greedy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.