zoukankan      html  css  js  c++  java
  • Covered Path

    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.

    Examples
    input
    Copy
    5 6
    4 2
    output
    Copy
    26
    input
    Copy
    10 10
    10 0
    output
    Copy
    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 = 26 meters.

    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.

    贪心也有狗头马尾,主要是不容易想到每秒最快的速度的条件

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    //#include <xfunctional>
    #define ll long long
    #define mod 1000000007
    using namespace std;
    int dir[4][2] = { { 0,1 },{ 0,-1 },{ -1,0 },{ 1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    
    int main()
    {
        int v1, v2, t, d;
        cin >> v1 >> v2 >> t >> d;
        int sum = 0;
        for (int i = 0; i < t; i++)
        {
            sum += min(v1 + d*i, v2 + d*(t - i -1));
        }
        cout << sum;
        return 0;
    }
     
  • 相关阅读:
    edgedb 内部pg 数据存储的探索 (四) 源码编译
    edgedb 内部pg 数据存储的探索 (二) 创建数据库命令说明
    edgedb 内部pg 数据存储的探索 (三) 源码包setup.py 文件
    python 集成cython && push 测试pip 仓库
    python 集成cython 简单测试
    click python cli 开发包
    转载一篇阿里云Terraform 开发指南
    zabbix 4.2 支持 timescledb 了
    edgedb 内部pg 数据存储的探索 (一)基本环境搭建
    Podman and Buildah for Docker users
  • 原文地址:https://www.cnblogs.com/dealer/p/12435040.html
Copyright © 2011-2022 走看看