【题目链接】: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. winedt (latex 编译器)解决中文的问题(CJK & CTEX)

    主要是导入相关的库支持: 1. CJK \usepackage{CJK}:CJK,是中日韩的英文首字母的组合,处理中文需要先导入这个包: \begin{CJK*}{GBK}{song}:默认句式,表示 ...

  2. angular 响应式自定义表单控件—注册头像实例

    1. 组件继承ControlValueAccessor,ControlValueAccessor接口需要实现三个必选方法 writeValue() 用于向元素中写入值,获取表单的元素的元素值 regi ...

  3. GO语言学习(四)GO语言语言结构

    Go Hello World 实例 Go 语言的基础组成有以下几个部分: 包声明 引入包 函数 变量 语句 & 表达式 注释 接下来让我们来看下简单的代码,该代码输出了"Hello ...

  4. POJ 3159 Candies 还是差分约束(栈的SPFA)

    http://poj.org/problem?id=3159 题目大意: n个小朋友分糖果,你要满足他们的要求(a b x 意思为b不能超过a x个糖果)并且编号1和n的糖果差距要最大. 思路: 嗯, ...

  5. (转)Vim练级攻略

    (转)Vim练级攻略 原文链接:http://coolshell.cn/articles/5426.html vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆 ...

  6. FPGA实现UHS的一些资料

    对使用FPGA和SD卡进行UHS模式通信的评估: 论文:基于FPGA的SD UHS-II卡控制器设计与实现 设计IP:SD UHS-II Host Controller 供应商: System Lev ...

  7. java測试网络连接是否成功并设置超时时间

    /** * 获取RMI接口状态 * * @return "0":服务正常,"1": 连接报错,"2":连接超时 */ @Override p ...

  8. [原]MFC中DIALOG(对话框)程序响应加速键(快捷键)

    [原]MFC中DIALOG(对话框)程序响应加速键(快捷键) 2014-8-6阅读266 评论0 新建一个对话框程序,项目名为Test,删除默认确定,取消和静态文本框控件.添加一个按钮,Caption ...

  9. Oracle学习(六):子查询

    1.知识点:能够对比以下的录屏进行阅读 SQL> --子查询所要解决的问题:问题不能一步求解 SQL> --查询工资比SCOTT高的员工信息 SQL> --(1)使用普通方法 SQL ...

  10. 借助gdb实现pstack

    pstack.sh: #! /bin/sh if [ -z $1 ] then echo "gdb script for print stack" echo "usage ...