[ 10.03 ]CF每日一题系列—— 534B贪心

时间:2021-09-13 13:58:29

Descripe:
  贪心,贪在哪里呢……

  给你初始速度,结尾速度,行驶秒数,每秒速度可变化的范围,问你行驶秒数内最远可以行驶多少距离

Solution:
  贪心,我是否加速,就是看剩下的时间能不能减到原始给定的结尾速度

#include <iostream>

using namespace std;

int main()
{
int v1,v2;
int t,d;
while(cin>>v1>>v2)
{
cin>>t>>d;
int ret = v1 + v2;
for(int i = 2;i < t;i++)
{
//找峰值 v1加速的最大 和 v剩下时间v2能允许加到的最大 中的最小值贪心一下
ret += min(v1 + (i-1) * d,v2 + (t-i) * d);
}
printf("%d\n",ret);
}
return 0;
} //#include <iostream>
//
//using namespace std;
//
//int main()
//{
// int v1,v2;
// int t,d;
// while(cin>>v1>>v2)
// {
// cin>>t>>d;
// int ret = v1 + v2;
// int upt = 0;
// int ext = t - 2;
// while(ext)
// {
// if(v1 + d > v2 + ext * d)
// {
// v1 = v2 + ext * d;
// ext--;
// ret += v1;
// break;
// }
// else
// {
// v1 += d;
// }
// ext--;
// //cout<<v1<<endl;
// ret += v1;
// }
// while(ext--)
// {
// v1 -= d;
// ret += v1;
// }
// printf("%d\n",ret);
// }
// return 0;
//}