VJ-Covered Path
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 |
---|
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 = 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<stdio.h>
int main()
{
int v1,v2,v,t,d;
int sum=0;
int speed[110]; /*記錄每個時間段速度*/
scanf("%d%d%d%d",&v1,&v2,&t,&d);
speed[1]=v1;
speed[t]=v2;
for(int i=2;i<t;i++)
{
v=speed[i-1]+d;
if(v>(t-i)*d+v2)
v=(t-i)*d+v2;
speed[i]=v;
}
for(int i=1;i<=t;i++)
sum+=speed[i];
printf("%d",sum);
return 0;
}
要得到通過的最長的路程,即要速度加到條件內的最大速度,並且在時間內減速回到v2。同時從v1,v2開始加速(兩邊往中間),如果從v1開始加的速度大於v2加的,那麼就不可以在時間內回到v2,最大的速度只能是從v2開始加的速度。
(國語と數學はあまりにも劣っていて、どのように説明するか分かりません)
相關推薦
VJ-Covered Path
Covered Path The on-board computer on Polycarp’s car measured that the car speed at the beginning of some section of the path equal
[VJ][暴力列舉]Covered Path
Covered Path Description The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1&
Codeforces 534B - Covered Path
col alt using out 速度 its cover include sync 534B - Covered Path 思路:貪心,每一秒取盡可能大速度。 畫張圖吧,不解釋了: 代碼: #include<bits/stdc++.h> using
CodeForces - 534B-Covered Path+思路
over problem 思路 加速 include blog mes str OS CodeForces - 534B 題意:給定初始和末尾的速度,和最大加速度和總時間,求出走的最長路程; 我一開始以為代碼寫起來會很繁瑣。。。 #include <iostrea
Node.js Path 模塊
工具 詳細 模塊 module tro ebp dex ble put var path = require(‘path‘); module.exports = { entry: ‘./app/index.js‘, output: { filename:
java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
java ... mod ons exc pen 方法 except open java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
【LeetCode】064. Minimum Path Sum
ive rom right ott path sum 處理 tom ber its 題目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom ri
Package gtk+-3.0 was not found in the pkg-config search path
path 二進制 all 項目 有時 rpm fedora ack share 問題描述: 在fedora21系統上通過rpmbuild構建fcitx的二進制包時出現以上錯誤,經老程序員指點:“是相應的開發包沒有安裝” 解決辦法: yum installl gtk3
LeetCode 64. Minimum Path Sum 20170515
tco path sum obj .com 最小 ima minimum type elif Given a m x n grid filled with non-negative numbers, find a path from top left to bottom r
[轉]The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
right clas rup b- row 添加按鈕 n) 1-1 自帶 完整錯誤信息: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS" AND ANY EXPRESS O
解決Visual C++ for Linux: -L"~/projects/path_to_lib_folder" 無法設置library search path的問題
一個 是個 映射 images 目的 ++ 用戶名 visual 技術 最近倒騰Linux C/C++項目。以目前的情況來說,要生成編譯(build)一個Linux工程腳本,首選的工具必定是CMake。這也是我之前Linux項目的首選。不過自從VS IDE支持Linux C
Set VM RDM disk to Round Bobin and set IOPS path to 1
iops rdm KB Related to IOPS settingAdjusting Round Robin IOPS limit from default 1000 to 1 (2069356)https://kb.vmware.com/selfservice/microsites/search
使用json path設置關聯
返回結果 格式 結束 .com 一行 使用 數據 報文 關聯 與正則表達式相比,這種方法會更簡單一些 1.現在需要獲取結果數據的登陸腳本上面添加後置[email protected]/* */ path 2.查看登陸腳本的返回結果,一般都是一個Key對應一個v
64. Minimum Path Sum
[] bottom blank prim from ini etc ++ i++ 題目: Given a m x n grid filled with non-negative numbers, find a path from top left to botto
POJ 3126 Prime Path SPFA
queue mes primer memset 改變 data- sprint ron ble http://poj.org/problem?id=3126 題目大意: 給你兩個四位的素數s和t,要求每次改變一個數字。使得改變後的數字也為素數,求s變化到t的最少變化次
The path to the driver executable must be set by the webdriver.gecko.driver system property;
pack 如果 leg ide rec sel window win find 今天安裝了webdriver後,編寫了一個測試小程序,但運行時控制臺報了這樣的錯誤: 1 Exception in thread "main" java.lang.IllegalStat
新建 jsp異常,The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
prop 選擇 library path per png class pro found 新項目,新建jsp頁面的時候報異常: Multiple annotations found at this line: - The superclass "java
node path模塊
color 為什麽 bsp 相對 base orm div 分隔 快樂 一、在nodejs中path模塊時使用頻率很高的模塊,其中不乏有很多API寫得很模糊,但仔細琢磨下來,也不是很難理解。 1.獲取文件所在路徑 var path = require(‘path‘); v
nodeJS之路徑PATH模塊
沒有 組成 use 路徑 api normalize file bin 空字符串 前面的話 path模塊包含一系列處理和轉換文件路徑的工具集,通過 require(‘path‘) 可用來訪問這個模塊。本文將詳細介紹path模塊 路徑組成 【path.dirn
oracle9i statspack 報告 分析 direct path read 等待事件
sql pin physical 100% ica statistic ffi 10.9 count(0 DB Name DB Id Instance Inst Num Release Cluster Host ----------