Codeforces534B:Covered Path
来源:互联网 发布:网络购物合同纠纷举证 编辑:程序博客网 时间:2024/06/05 20:20
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.
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.
Print the maximum possible length of the path segment in meters.
5 64 2
26
10 1010 0
100
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.
题意:车在开始那一秒和结束那一秒的速度为V1,V2 ,给出总共行驶的时间,而且每秒的速度增加与减少最多为d,要求出最大的行驶距离
思路:我们假设最高速度为第i秒时,那么从1~i是一个以v1为起始项的的递增序列,而从t~i则是以v2为起始项的递增序列,那么枚举i的位置求出来的值必然是最大的
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define ls 2*i#define rs 2*i+1#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,x) memset(a,x,sizeof(a))#define w(a) while(a)#define LL long longconst double pi = acos(-1.0);#define Len 63#define mod 19999997const int INF = 0x3f3f3f3f;int v1,v2,t,d,sum;int main(){ int i,j,k; w(~scanf("%d%d%d%d",&v1,&v2,&t,&d)) { sum = 0; up(i,0,t-1) sum+=min(v1+i*d,v2+(t-i-1)*d); printf("%d\n",sum); } return 0;}
- Codeforces534B:Covered Path
- Covered Path
- codeforces Covered Path
- cf. Covered Path
- Covered Path CodeForces
- Codeforces 534B Covered Path
- codeforces-534B-Covered Path
- CF 534B Covered Path
- CodeForces 534B Covered Path
- CodeForces 534B Covered Path
- #298 (div.2) B. Covered Path
- Codeforces 534B Covered Path(贪心)
- CodeForces 534B Covered Path 【贪心】
- codeforces 534B Covered Path-思维
- codeforces 534B B. Covered Path(dp)
- CodeForce 534B Covered Path(简单推理)
- Codeforces 534B Covered Path【有点奇怪的思维+贪心】
- Mongodb Covered Indexes
- 从零开始启动一个项目,需要哪些准备工作
- 华为在线测试题[基础篇]--求最小公倍数
- MapFileView示例
- 用Hexo写博客 - ERROR Local hexo not found in xxx
- 用wordpress搭建博客
- Codeforces534B:Covered Path
- 剑指offer--孩子们的游戏(圆圈中最后剩下的数)
- 织梦DEDE网站后台如何上传附件
- linux常用命令整理总结之一
- 创建命名共享内存
- linux常用命令整理总结之二
- linux常用命令整理之三
- Emacs的C语言排版缩进模式选择
- 黑马程序员_日记58_HashMap自定义对象存取练习