Educational Codeforces Round 137 (Rated for Div. 2) - E. FTL
DP
题意
有个 BOSS 有 \(H\;(1<=H<=5000)\) 血量,\(s\) 点防御
有两种武器可用攻击 BOSS,伤害分别为 \(p_1,p_2\;(s<min(p_1,p_2)<=5000)\), 冷却时间分别为 \(t_1,t_2\;(1<=t_1,t_2<=10^{12})\)
每一时刻如果 cd 好了可以选择攻击,造成 \(p_i-s\) 点伤害;如果两个武器一起攻击可以造成 \(p_1+p_2-s\) 点伤害
0 时刻两个武器都刚进入 cd,求将 BOSS 消灭的最短时间
思路
- 可以选择攻击的时刻一定是 \(p_1\) 或 \(p_2\) 的倍数,并且每次至少造成 1 点伤害,因此最多有 \(H\) 个需要抉择的时刻 \(T_i\)
- 当某时刻两个武器同时发射时,之后的操作就成了一个子问题
- 可以设 \(f[h]\) 为两个武器都刚进入 cd,打掉 h 血的最短时间,枚举 \(T_i\), 作为第一次刻意等待令两个武器同时发射的时刻,求出前 \(T_i\) 时间正常操作(即 cd 好了就放)造成的伤害 \(tot\), \(f[h]=min(f[h],f[h-tot]+T_i)\)
代码
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef pair<int, int> PII;
const int N = 5e3 + 10;
int p[3], H, s;
ll t[3], cnt[3];
ll f[N];
vector<ll> vt;
ll lcm(__int128 a, __int128 b)
{
__int128 t = a / __gcd(a, b) * b;
if (t >= (__int128)2e18)
t = 2e18;
return t;
}
void presolve()
{
if (t[1] > t[2])
{
swap(t[1], t[2]);
swap(p[1], p[2]);
}
p[0] = p[1] + p[2] - s;
p[1] -= s, p[2] -= s;
t[0] = lcm(t[1], t[2]);
for (int i = 1; i * p[1] <= H; i++)
vt.push_back(i * t[1]);
for (int i = 1; i * p[2] <= H; i++)
vt.push_back(i * t[2]);
sort(vt.begin(), vt.end());
vt.erase(unique(vt.begin(), vt.end()), vt.end());
}
void solve()
{
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int h = 1; h <= p[1]; h++)
f[h] = t[1];
for (int h = p[1] + 1; h <= H; h++)
{
for (auto T : vt)
{
if (T % t[0] == 0)
{
cnt[0] = T / t[0];
cnt[1] = T / t[1] - cnt[0];
cnt[2] = T / t[2] - cnt[0];
}
else if (T % t[1] == 0)
{
if (T < t[2])
{
cnt[1] = T / t[1];
cnt[2] = cnt[0] = 0;
}
else
{
cnt[1] = T / t[1];
cnt[2] = T / t[2];
ll TT = (cnt[2] - 1) * t[2];
cnt[0] = TT / t[0] + 1;
cnt[1] -= cnt[0], cnt[2] -= cnt[0];
}
}
else
{
cnt[2] = T / t[2];
cnt[1] = T / t[1];
ll TT = (cnt[1] - 1) * t[1];
cnt[0] = TT / t[0] + 1;
cnt[1] -= cnt[0], cnt[2] -= cnt[0];
}
ll tot = 0;
for (int i = 0; i < 3; i++)
tot += cnt[i] * p[i];
ll now = 0;
if (tot >= h)
now = T;
else
now = T + f[h - tot];
f[h] = min(f[h], now);
}
}
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> p[1] >> t[1] >> p[2] >> t[2] >> H >> s;
presolve();
solve();
ll ans = f[H];
cout << ans << endl;
return 0;
}
Educational Codeforces Round 137 (Rated for Div. 2) - E. FTL的更多相关文章
- Educational Codeforces Round 137 (Rated for Div. 2) A-F
比赛链接 A 题解 知识点:数学. \(4\) 位密码,由两个不同的数码组成,一共有 \(C_4^2\) 种方案.从 \(10-n\) 个数字选两个,有 \(C_{10-n}^2\) 种方案.结果为 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- SQL 之 SELECT语句
1.展示所有列语法 select * from table; #table表示表名 示例: select * from a 2.展示指定列语法 select column1, column2, ... ...
- 云知声: 基于 JuiceFS 的超算平台存储实践
云知声从一家专注于语音及语言处理的技术公司,现在技术栈已经发展到具备图像.自然语言处理.信号等全栈式的 AI 能力,是国内头部人工智能独角兽企业.公司拥抱云计算,在智慧医疗.智慧酒店.智慧教育等方面都 ...
- last-child可能你也会踩的坑
旧文章从语雀迁移过来,原日期为2021-07-14 问题 当时写在写一个列表,列表每一项需要下面加下划线,最后一项不加下划线.第一时间,想到使用 :``last-child 这个伪类来实现. 当时的代 ...
- vue3 递归组件 树形组件
递归组件 第一种方式,直接自己调用自己 Tree.vue <template> <div class="tree"> <div v-for=" ...
- Dubbo架构设计与源码解析(二) 服务注册
作者:黄金 一.Dubbo简介 Dubbo是一款典型的高扩展.高性能.高可用的RPC微服务框架,用于解决微服务架构下的服务治理与通信问题.其核心模块包含 [RPC通信] 和 [服务治理] ,其中服务治 ...
- 一问读懂Web3 架构
最近看了一些Web3.0的文章,总结了一些个人的理解: Web3.0 通过区块链基础设施管理用户数据,重构用户和互联网平台之间的关系和交互,重新定义了互联网应用的架构方式和交互模式. Web 1.0 ...
- AtCoder Beginner Contest 282 G - Similar Permutation
套路题 题意 求有多少个 \(1\) 到 \(n\) 的排列满足恰有 \(k\) 对在排列中相邻的数满足前小于后 \(2 \leq n \leq 500, 0 \leq k \leq (n - 1)\ ...
- 在Ubuntu上安装OpenShift并使用
服务器信息 在阿里云买了个抢占式的服务器,地区为华南广州,系统为Ubuntu 20.04,8核16GB. 安装Docker 命令如下: $ apt-get update -y $ apt-get up ...
- Failed to find "GL/gl.h" in "/usr/include/libdrm"
环境qt5.12.3 deepin15.10 使用cmake构建项目时报错,网上查询了一下发现时未安装opengl,于是安装便是了 sudo apt install mesa-common-dev 问 ...
- 构建api gateway之 负载均衡
什么是负载均衡 负载均衡,英文名称为Load Balance,其含义就是指将负载(工作任务)进行平衡.分摊到多个操作单元上进行运行 以下为几种负载均衡策略介绍 1.随机(Random) 大家很多时候说 ...