[none]CodeForces 534B

题意:
给出起点和终点的速度还有时间,问在速度上下拨动不能超过d的情况下,求出最大的路程。

分析:
其实怎么做还是得枚举峰值,那么峰值改怎么求呢?贪心的一直+d,后面保证还能减回v2,那么就每次取两条向上和向下的线的最小值就可以了。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#define read freopen("q.in","r",stdin)
#define LL long long
#define maxn 1000005
using namespace std;

int main()
{
   int t,d,v1,v2,res=0;
   while(~scanf("%d%d%d%d",&v1,&v2,&t,&d))
   {
       res=0;
       res+=(v1+v2);
       for(int i=2;i<t;i++)
           res+=min(v1+(i-1)*d,(t-i)*d+v2);
       cout<<res<<endl;
   }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章