DP

Problem - E - Codeforces

题意

有个 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 消灭的最短时间

思路

  1. 可以选择攻击的时刻一定是 \(p_1\) 或 \(p_2\) 的倍数,并且每次至少造成 1 点伤害,因此最多有 \(H\) 个需要抉择的时刻 \(T_i\)
  2. 当某时刻两个武器同时发射时,之后的操作就成了一个子问题
  3. 可以设 \(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的更多相关文章

  1. Educational Codeforces Round 137 (Rated for Div. 2) A-F

    比赛链接 A 题解 知识点:数学. \(4\) 位密码,由两个不同的数码组成,一共有 \(C_4^2\) 种方案.从 \(10-n\) 个数字选两个,有 \(C_{10-n}^2\) 种方案.结果为 ...

  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 ...

  3. 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 ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. 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 ...

  7. 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 ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. 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 < ...

  10. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

随机推荐

  1. 注意看,她叫小美,在地址栏输入URL地址后发生了什么?

    注意看,这个用户叫小美,他在地址栏输入了一串URL地址,然后竟然发生了不可思议的事情! 01.输入URL发生了什么? 从输入URL开始,到页面呈现出来,简单来说分为四个步骤: ① 建立连接:建立与服务 ...

  2. 学习ASP.NET Core Blazor编程系列十九——文件上传(下)

    学习ASP.NET Core Blazor编程系列文章之目录 学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应 ...

  3. [R语言] ggplot2入门笔记3—通用教程如何自定义ggplot2

    通用教程简介(Introduction To ggplot2) 代码下载地址 以前,我们看到了使用ggplot2软件包制作图表的简短教程.它很快涉及制作ggplot的各个方面.现在,这是一个完整而完整 ...

  4. [seaborn] seaborn学习笔记1-箱形图Boxplot

    文章目录 1 箱形图Boxplot 1. 基础箱形图绘制 Basic boxplot and input format 2. 自定义外观 Custom boxplot appearance 3. 箱型 ...

  5. 如何指定多个项目的 InternalsVisibleTo

    InternalsVisibleTo 属性允许你指定一个或多个程序集,这些程序集可以访问当前程序集中的内部类型.经常在进行单元测试时使用,例如,你可以在一个项目中定义一个内部类型,然后在另一个项目中进 ...

  6. Zotero自定义引文样式

    注意 在实际使用中发现还是有许多与要求不同的地方,之后会再次进行修改,特此记录 -----2022/11/28 16:57 目标格式: 期刊:[序号]作者.题名[J].刊名,出版年份,卷号 ( 期号 ...

  7. Blazor Pdf Reader PDF阅读器 组件 更新

    Blazor Pdf Reader PDF阅读器 组件 https://www.nuget.org/packages/BootstrapBlazor.PdfReader#readme-body-tab ...

  8. idea正则替换

    将非 (股权)的替换成 股权

  9. 五种传统IO模型

    五种传统I/O模型 作者:tsing 本文地址:https://www.cnblogs.com/TssiNG-Z/p/17089759.html 简介 提起I/O模型, 就会说到同步/异步/阻塞/非阻 ...

  10. SQLSERVER 的 truncate 和 delete 有区别吗?

    一:背景 1. 讲故事 在面试中我相信有很多朋友会被问到 truncate 和 delete 有什么区别 ,这是一个很有意思的话题,本篇我就试着来回答一下,如果下次大家遇到这类问题,我的答案应该可以帮 ...