CF Covered Path (贪心)
2015-04-20 22:25
447 查看
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
output
input
output
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 哈哈,终于可以完全理解的A出一道贪心题了。假设每个点的速度是V,剩余的时间是T_S,加速量是X,那么需要满足 V + X <= V_2 + T_S * d,以此来更新每个点的速度就行。
#include <iostream> #include <cstdio> using namespace std; int main(void) { int v_1,v_2,t,d; int sum = 0; cin >> v_1 >> v_2; cin >> t >> d; sum += v_1; int v = v_1; for(int i = 2;i <= t;i ++) for(int j = d;j >= -d;j --) if(v + j <= v_2 + (t - i) * d) { v += j; sum += v; break; } cout << sum << endl; return 0; }
相关文章推荐
- cf. Covered Path
- CF - 797A. k-Factorization - 思维+贪心+数学
- CF - 807B. T-Shirt Hunt - 贪心+模拟
- SDUT3903 CF(dp+贪心) 2017山东ACM省赛
- CF - 794C. Naming Company - 贪心+排序+模拟+字符串处理
- HDU_4912 Path on the tree 2014多校5 贪心+LCA
- [贪心] cf883K Road Widening
- CF 700E Cool Slogans 线段树+后缀数组贪心求解
- CF 118C - Fancy Number 贪心+字符串处理
- CF - 246 - B. Increase and Decrease(贪心)
- CF-45D. Event Dates(贪心)
- nyoj 1216——整理图书 CF 229D—— Towers——————【dp+贪心】
- CF 402-D 贪心
- CF 496C(Removing Columns-贪心取字典序)
- Covered Path CodeForces - 534B
- CF 515D 图,贪心
- cf#VK Cup 2015 - Qualification Round 2-C - Name Quest-贪心
- CF(437C)The Child and Toy(贪心)
- CF 505B(Anton and currency you all know-贪心)
- CF 329B(Biridian Forest-贪心-非二分)