【题目链接】: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. 自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画

    自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画 下载Demo:http://download.csdn.net/detail/menglele1314/8775 ...

  2. sql基础知识集锦

    Sql常用语法 下列语句部分是Mssql语句,不可以在access中使用. SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT ...

  3. Day1:循环语句(While,For)

    一.while循环 while 条件: 条件为真执行的语句 esle: 条件为假执行的语句 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author: ...

  4. loadrunne-- Analysis 分析器

    本文转自:https://www.cnblogs.com/Chilam007/p/6445165.html Analysis简介 分析器就是对测试结果数据进行分析的组件,它是LR三大组件之一,保存着大 ...

  5. 动态规划 —— 求解通配符问题(wildcard)

    he?p help, heap, √ hellp, × *p*(必须包含 p,左右随意) help, papa, √ hello × *bb*(必须包含连续的两个 bb,左右随意) babbc √ 1 ...

  6. 缓存(cache)的理解

    缓存的特点: 读取速度很快,容量相比硬盘较小: 缓存在实现时,本质上仍然是一块内存区域: cache 机制的一个核心关注点还在于,究竟什么样的数据应该放在缓存中,显然不是所有,那就应当是部分,就应该是 ...

  7. mootools常用特性和示例(基础篇2)

    接着上一篇:mootools常用特性和示例(基础篇1) 1.表单操作 html: <form id="myForm" action="submit.php" ...

  8. linux中内存泄漏的检測(一)最简单的方法

    什么是内存泄漏 内存泄漏是指程序动态申请的内存在使用完后没有释放,导致这段内存不能被操作系统回收再利用. 比如这段程序,申请了4个字节的空间但没有释放,有4个字节的内存泄漏. #include < ...

  9. swift项目第十天:网络请求工具类的封装

    import UIKit /* 必须先导入头文件:import AFNetworking */ import AFNetworking //MARK:-0:定义枚举:以枚举定义请求网络的get和pos ...

  10. 如何把canvas元素作为网站背景总结详解

    如何把canvas元素作为网站背景总结详解 一.总结 一句话总结:最简单的做法是绝对定位并且z-index属性设置为负数. 1.如何把canvas元素作为网站背景的两种方法? a.设置层级(本例代码就 ...