【题目链接】:http://codeforces.com/contest/534/problem/B

【题意】



你在t秒内可以将车的速度任意增加减少绝对值不超过d;

然后要求在一开始车速为v1,t秒之后车速变为v2;

问你这段t时间内,车最多能行驶多远。

【题解】



枚举车“最大速度”v

看看车到达这个速度之后,然后回到速度v2(也就是说v是可能小于v2的,所以最大速度加了引号”)看看可不可行;

如果能在到达最大速度之后又回到速度v2(在t时间内);

那么记下回到v2的时间t1

在到达v和回到v2这段时间内的位移+(t-t1)*max(v,v2)就是答案了



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; int v1, v2, t, d,ans = 0; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(v1), rei(v2), rei(t), rei(d);
rep1(v, v1, v1 + t*d)
{
int temp = 0;
int now = 0, vv = v1;
while (vv < v)
{
temp += vv;
vv += d;
vv = min(vv, v);
now++;
if (now > t)
break;
}
if (now > t) continue;
if (vv < v2)
{
while (vv < v2)
{
temp += vv;
vv += d;
vv = min(vv, v2);
now++;
if (now > t)
break;
}
if (now > t)
continue;
now++;
temp += vv;
}
else
if (vv > v2)
{
while (vv > v2)
{
temp += vv;
vv -= d;
vv = max(vv, v2);
now++;
if (now > t)
break;
}
if (now > t)
continue;
now++;
temp += vv;
}
else
if (vv == v2)
{
now++;
temp += vv;
}
temp += max(v, vv)*(t - now);
ans = max(ans, temp);
}
printf("%d\n", ans);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 534B】Covered Path的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【25.64%】【codeforces 570E】Pig and Palindromes

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 752F】Santa Clauses and a Soccer Championship

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

  8. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【33.33%】【codeforces 586D】Phillip and Trains

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. Android 解决RecyclerView删除Item导致位置错乱的问题

    RecyclerView的刷新分为内容变化和结构变化,结构变化比如remove和insert等并不会导致viewholder的更新,所以有时候我们使用 notifyItemRemoved(positi ...

  2. (转)Oracle命令

    转自:http://www.cnblogs.com/NaughtyBoy/p/3181052.html Oracle登录命令 1.运行SQLPLUS工具 C:\Users\wd-pc>sqlpl ...

  3. 【Codeforces Round #433 (Div. 2) C】Planning

    [链接]h在这里写链接 [题意] 让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样. 且ti>=i必须成立. [题解] 分解一下成为∑ti*gi ...

  4. ubuntu,右键添加在终端中打开

    右键中添加"在终端中打开" 在终端输入  sudo apt-get install nautilus-open-terminal 重新启动, 进入操作系统就会发现单击鼠标右键就会出 ...

  5. Android, IOS 史上最强多语言国际化,不仅第一次会尾随系统,并且会保存用户的语言设置

    劲爆消息,我提供源代码了.你能够先看完再下载.也能够先下载再看完, android源代码地址: https://github.com/hebiao6446/------Bluetooth-Androi ...

  6. (嵌入式开发)自己写bootloader之编写第二阶段

    内核编译(make)之后会生成两个文件,一个Image,一个zImage,其中Image为内核映像文件,而zImage为内核的一种映像压缩文件,Image大约为4M,而zImage不到2M.     ...

  7. LA 3887 - Slim Span 枚举+MST

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  8. 3、Unicode\UTF-8\GBK 区别和联系

    字符编码:Unicode和UTF-8之间的关系 可以参考下面blog:https://blog.csdn.net/xiaolei1021/article/details/52093706/ 这篇文章写 ...

  9. springboot下静态资源的处理(转)

    在SpringBoot中有默认的静态资源文件相关配置,需要通过如下源码跟踪: WebMvcAutoConfiguration-->configureResourceChain(method)-- ...

  10. SQLite header and source version mismatch解决方案

    SQLite header and source version mismatch 最近需要用到sqlite,去官网下了一个编译安装后打开sqlite3出现SQLite header and sour ...