Codeforces Round #298 (Div. 2) B. Covered Path

Source: Internet
Author: User

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

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.