zoukankan      html  css  js  c++  java
  • cf 534B. Covered Path

    B. Covered Path
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.

    Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.

    Input

    The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

    The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.

    It is guaranteed that there is a way to complete the segment so that:

    • the speed in the first second equals v1,
    • the speed in the last second equals v2,
    • the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.
    Output

    Print the maximum possible length of the path segment in meters.

    Sample test(s)
    input
    5 6
    4 2
    output
    26
    input
    10 10
    10 0
    output
    100
    Note

    In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26meters.

    In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.

    题意是说一辆车,每秒内的速度恒定...第I秒到第I+1秒的速度变化不超过D。初始速度为V1,末速度为V2,经过时间t,问最远能走多远。

    策略就是尽可能加速...加到某个时间,如果在这个时间不开始减速就回不到V2了。

    从后往前预处理下每秒钟能达到的最大速度(如果超过这个速度,将不能减回到V2)

    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    const int N=1E2+5;
    const int inf=8E9;
    int a[N],m[N];
    int v1,v2,t,d,tmp,p,ans,n;
    
    
    int main()
    {
        cin>>v1>>v2>>t>>d;
        p = inf;
        memset(a,0,sizeof(a));
        a[1]= v1;
        tmp = v2;
        m[t]= v2;
        for ( int i = t-1 ; i >= 1; i--)
        {
            tmp = tmp+d;
            m[i] = tmp;
        }
        for ( int i =2 ;i <= t; i++ )
        {
            if (a[i-1]+d<=m[i])
            {
                a[i] = a[i-1] + d;
            }
            else
            {
                a[i] = m[i];
                p = i;
                break;
            }
        }
        ans = 0;
        for ( int i = p ; i <= t; i++ )
            a[i] = m[i];
        for ( int i = 1; i <= t ; i++ )
        {
            if (i<p)
                ans = ans + a[i];
            else ans = ans + m[i];
        }
       // for ( int i = 1; i <= t ; i++)
       //     cout<<"a[i]:"<<a[i]<<endl;
        cout<<ans<<endl;
    
        return 0;
    }
  • 相关阅读:
    PAT查找题---1032 挖掘机技术哪家强 (20分)
    PAT查找题---1028 人口普查 (20分)
    PAT查找题---1004 成绩排名 (20分)
    01_1JAVA简介
    01考试简介
    shell时间变量拼接问题
    如何将oracle查询的结果传输给变量
    生产环境邮件问题总结
    mutt+msmtp做linux邮件客户端
    linux配置邮件客户端
  • 原文地址:https://www.cnblogs.com/111qqz/p/4427472.html
Copyright © 2011-2022 走看看