[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 meters per second, and in the end it is v2meters 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.

描述:

一个小车起始速度为v1,末速度为v2,给出时间t,和最大加速度(-d--d)

求小车在 t 时间内的最大路程。

正确解法:

时间从 t==2 开始枚举,从d— -d开始枚举加速度。

当满足 现在的速度v 加上加速度 再减去剩余时间*d <=v2 时,此时的加速度就是目前所能加的最大加速度。

万一小车加速,要保证它在剩余时间内可以减速到 v2

(第一次见到枚举加速度,要好好记下来)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<string>
 6 #include<cstring>
 7 using namespace std;
 8 int b[1000010] = {0};
 9 int main()
10 {
11     int v1, v2,t,d,v;
12     cin >> v1 >> v2 >> t >> d;
13     long long ans = v1;
14     v = v1;    t=t-1;
15     while (t) {
16         for (int i = d; i >= -d; i--)
17             if (v + i - (t - 1)*d <= v2)
18             {
19                 ans += v + i;
20                 t--;
21                 v = v + i;
22                 break;
23             }
24     }
25     cout << ans << endl;
26     return 0;
27 }

原文地址:https://www.cnblogs.com/Kaike/p/9887163.html

时间: 2024-10-01 04:05:18

[VJ][暴力枚举]Covered Path的相关文章

[poj1054] The Troublesome Frog 暴力枚举+剪支

The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 11339 Accepted: 3383 Case Time Limit: 500MS Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a well-deserved reputation, b

hdu5616 暴力枚举

2017-08-25 20:08:54 writer:pprp 题目简述: ? HDU 5616? n个砝码,可以放在天平左右两侧或不放? m次询问,每次询问是否可以测出给定重量? 1 ≤ n ≤ 20? 1 ≤ m ≤ 100 这道题采用枚举的思路的话实现起来还是有点困难的, 要实现的功能是对每个砝码进行处理,加到左边, 加到右边,或者是不加 看了大神的代码,感觉很巧妙, 设置了两个标记数组 vis1[2005], vis2[2005] 一个vis1用来记录当前已经可以实现的重量 另一个vis

hdu4282A very hard mathematic problem 暴力枚举

//给出k //找x,y,z使得x^z+y^z+x*y*z = k //x,y,z都为正整数x<y,z>1问有多少种方法 //当z = 2时,可以看到左边是一个完全平方 //而当z>=3时,可以暴力枚举x,y //由于k<2^31所以x<2^(31/3)枚举复杂度可以过 #include<cstdio> #include<cstring> #include<iostream> #include<cmath> using name

hdu 5247 找连续数【暴力枚举】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5247 分析:这道题是2015百度之星初赛1的2题,当时没看这道题 是队友看的,比完以后也做了一下,思路大体都是一样的,就是 暴力枚举,因为k<=1000,那么我们可以每一点x为起点跑[x,x+999] 这段区间,把每得到一段连续的子区间[x,?],则num[len]++(len=size([x,?])); 这样就可以了,最后num数组里就是对应的答案 献上代码: #include<stdio.h&

HDU 4770 Lights Against Dudely 暴力枚举+dfs

又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ czy Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1360    Accepted Subm

ZOJ3818-Pretty Poem(暴力枚举)

题目链接 题意:求所给字符串是否符合ABABA或者ABABCAB的形式,如果可以的话输出Yes,不可以的话为No. 思路:暴力枚举A和B的长度,再用从长度减去3倍的AB长度,即为C的长度,看组合而成的字符串是否与给定的相等.在这里string中的substr函数是个好东西. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <a

uva10892(暴力枚举)

把n的所有因子求出来,总数不会太多,所以直接O(n2)的暴力枚举所有对行不行. 有几个细节要注意,详见代码. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include<set> #include<vector> #include<algorit

暴力枚举 + 24点 --- hnu : Cracking the Safe

Cracking the Safe Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 46, Accepted users: 12 Problem 12886 : No special judgement Problem description Secret agent Roger is trying to crack a safe containing evil Syr

HNU 12886 Cracking the Safe(暴力枚举)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数,要你判断用 + .- . * ./.四种运算能不能得到一个结果为24的式子,可以用括号. 解释一下测试的第四组样例:应该是6 / (1 - 3 / 4) 暴力枚举三种符号分别是什么,然后枚举这三种符号运算的顺序,然后枚举这四个数字的24种排列方式,时间是4^3 * 6 * 24 然后注意要用double型,