【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;}elseif (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;}elseif (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;
}
转载于:https://www.cnblogs.com/AWCXV/p/7626512.html
【codeforces 534B】Covered Path相关推荐
- 【Codeforces - 1000C】Covered Points Count(思维,离散化,差分)
题干: You are given nn segments on a coordinate line; each endpoint of every segment has integer coord ...
- 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)
题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...
- 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)
题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...
- 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)
题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...
- 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)
题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...
- 【python初级】os.path.isfile(path)判断路径是否为文件
[python初级]os.path.isfile判断路径是否为文件 背景 示例 背景 os.path.isfile(path)判断路径是否为文件. import os help(os.path.isf ...
- 【CodeForces 997C】Sky Full of Stars(组合计数)
题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- 【codeforces 508B】Anton and currency you all know
[题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...
- 【codeforces 711B】Chris and Magic Square
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...
最新文章
- Siri不行了?微软小冰或许是未来的方向
- python3 字符串总结
- matlab高中必修三数学模拟,基于MATLAB的模拟调制实验报告
- charles都踩过哪些坑_开水果店的你,踩过了哪些坑?
- Vaadin和DukeScript中的Hello World
- python 内置模块-re
- c 正则去掉html标签,C#用正则表达式去掉Html中的script脚本和html标签
- ESXi vSphere Client中copy paste如何启用
- C Tricks(十二)—— 获取字符数组的末尾元素
- 连接和关闭资源工具类
- 一、部署虚拟环境来安装Linux系统
- 贪心算法之哈夫曼编码问题
- [HYSYS学习]逻辑单元-循环器
- 数字滤波算法——程序判断滤波
- validation
- spring容器的refresh方法分析
- ajax成功后没有执行函数,ajax请求成功但不执行success-function回调函数的问题
- 专家推荐面渣逆袭:JVM经典五十问,这下面试稳了
- 使用代理爬去微信公众号_微信公众号怎么去推广运营?企业微信公众号要如何运营?微信公众号运营技巧,你get了吗?微信怎么去推广运营?...
- HTML5期末大作业:动物网站设计——宠物狗(10页) HTML+CSS+JavaScript 大学生静态网页设计 dw宠物网页设计 狗狗网页设计html web课程设计网页规划与设计...