【codeforces 534B】Covered Path
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【30.36%】【codeforces 740D】Alyona and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.64%】【codeforces 570E】Pig and Palindromes
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 752F】Santa Clauses and a Soccer Championship
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【29.89%】【codeforces 734D】Anton and Chess
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【33.33%】【codeforces 586D】Phillip and Trains
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- BigBoss按键映射
// BigBoss: SBSettings Toggle Spec 按键映射 http://thebigboss.org/guides-iphone-ipod-ipad/sbsettings-tog ...
- Android中CursorLoader的使用、原理及注意事项
前言 最近在项目中涉及到了即时聊天,因此不可避免地要用到实时刷新的功能,因为在以前的项目中见到别人使用CursorLoader+CursorAdapter+ContentProvider的机制来实现实 ...
- 高级Java工程师必备 ----- 深入分析 Java IO (三)
概述 Java IO即Java 输入输出系统.不管我们编写何种应用,都难免和各种输入输出相关的媒介打交道,其实和媒介进行IO的过程是十分复杂的,这要考虑的因素特别多,比如我们要考虑和哪种媒介进行IO( ...
- dp hdu5653 xiaoxin and his watermelon candy
传送门:点击打开链接 题意:有n个箱子排成一排,有m个炸弹.位置告诉你.如今炸弹的左边伤害和右边伤害能够自己控制,要求 每一个炸弹炸的箱子数的累乘,输出答案取log2并乘以1e6 思路:直接2for ...
- 一次性能优化将filter转换
有一条SQL性能有问题,在运行计划中发现filter.遇到它要小心了,类似于nestloop.我曾经的blog对它有研究探索运行计划中filter的原理.用exists极易引起filter. 优化前: ...
- HDU 1215 七夕节 数学题~
http://acm.hdu.edu.cn/showproblem.php?pid=1215 题目大意: 找对象的题...汗..将你的编号(唯一)的所有因子加起来,所得到的的另一个编号的主人就是你的另 ...
- MFC屏蔽 WindowS按键
LRESULT CALLBACK LowLevelKeyboardPorc(int nCode,WPARAM wParam,LPARAM lParam)//屏蔽按键的真正实现方法{ BOOL fEat ...
- js如何将字符串作为函数名调用函数
js将如何字符串作为函数名调用函数 一.总结 一句话总结:用eval来实现.eval可以执行参数字符串. 二.js将字符串作为函数名调用函数 比如我现在有一个字符串str = "func_a ...
- 洛谷 P3112 后卫马克Guard Mark
->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...
- 【57.14%】【codeforces 722B】Verse Pattern
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...