Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

B. Covered Path

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/534/problem/B

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 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 Input

input1
5 6
4 2
input2
10 10
10 0
 

Sample Output

26
 
100

HINT

题意

啊,给你初速度和末速度,给你运动时间,和最大加速度

当然,每一秒的速度都是整数,然后问你在这种情况下,路程最大是多少

题解:

啊,暴力枚举每秒钟加多少就好啦,肯定是越早加速越好啦

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//************************************************************************************** int main()
{
int v1,v2;
cin>>v1>>v2;
int d,t;
cin>>t>>d;
int ans=v1;
for(int i=;i<=t;i++)
{
for(int j=d;j>=-d;j--)
{
if(v1+j-(t-i)*d<=v2)
{
v1=v1+j;
break;
}
}
ans+=v1;
//cout<<v1<<endl;
}
cout<<ans<<endl;
}
上一篇:微信小程序——自定义图标组件


下一篇:Alamofire源码解读系列(一)之概述和使用