Triple Attack 题解

· · 闲话

AD

My Blog

Solution

test 1~3

### test 4\~7 注意到 $health = 10$,非常小,我们可以设计一个 dfs: ```cpp void dfs(int h, int t, int t1, int t2, int t3) ``` 其中 $h$ 表示打掉的血量,$t$ 表示所用的时间,$t_{1 \sim 3}$ 表示三种武器距离下次攻击最小需要的时间。 每次 dfs 可以有四种情况,分别是使用第一种武器,使用第二种武器,使用第三种武器,和放大招。 这里需要注意,有可能使用的武器剩下的时间比较长,而剩下两种比较短,所以在计算伤害时,要加上剩下两种武器在这段时间里的伤害。 ### test 12\~15 考虑 dp,$dp_i$ 表示打掉 $i$ 的伤害至少需要的时间,每次枚举其中两种武器使用的次数即可转移。 ### test 21\~25 还是考虑 dp,枚举打掉的伤害 $i$,然后枚举其中一种武器的使用次数,这时会有两种情况,使用大招和不使用大招,以第一种武器作为例子: - 不使用大招的情况,原有的伤害是 $i$,第一种武器伤害是 $j (a_1 - armor)$,需要的时间是 $jt_1$,那么第二种武器的伤害是 $\left\lfloor{\dfrac{jt_1}{t_2}}\right\rfloor (a_2 - armor)$,第三种武器的伤害是 $\left\lfloor{\dfrac{jt_1}{t_3}}\right\rfloor (a_3 - armor)$,一共是 $i + j (a_1 - armor) + \left\lfloor{\dfrac{jt_1}{t_2}}\right\rfloor (a_2 - armor) + \left\lfloor{\dfrac{jt_1}{t_3}}\right\rfloor (a_3 - armor)$。 - 使用大招的情况,原有的伤害是 $i$,第一种武器伤害是 $(j - 1)(a_1 - armor)$,加上大招的时间是 $jt_1$,那么第二种武器的伤害是 $\left\lfloor{\dfrac{jt_1 - t_2}{t_2}}\right\rfloor (a_2 - armor)$,第三种武器的伤害是 $\left\lfloor{\dfrac{jt_1 - t_3}{t_3}}\right\rfloor (a_3 - armor)$,大招的伤害是 $(a_1 + a_2 + a_3 - armor)$,一共是 $i + (j - 1)(a_1 - armor) + \left\lfloor{\dfrac{jt_1 - t_2}{t_2}}\right\rfloor (a_2 - armor) + \left\lfloor{\dfrac{jt_1 - t_3}{t_3}}\right\rfloor (a_3 - armor) + (a_1 + a_2 + a_3 - armor)$。 最后,我们把伤害 $> health$ 的情况都归入 $dp_{health}$ 中,防止溢出。 ### test 8\~11 & test 16\~20 考虑 $j$ 的上界,$j$ 太大会导致伤害非常大,是没有意义的。武器的使用次数最多为 $\max\left\{ {\left\lceil \dfrac{health}{a_k - armor} \right\rceil}\right\}$。($k \in \{ 1, 2, 3 \}$)在这些测试点中 $a_k - armor \ge 10$。$j_{max} \le 1000$,dp 运算的次数最多为 $10000 \times 1000 = 10^7$ 次,可以通过此题。 ## Code ```cpp #include <bits/stdc++.h> #define int long long using namespace std; const int N = 50005; int dp[N]; inline int mn(int a, int b) { return (a > b ? b : a); } inline int mx(int a, int b) { return (a > b ? a : b); } int a1, t1, a2, t2, a3, t3, health, armor, s1, s2, s3, t, Max; inline void sol() { memset(dp, 0x3f, sizeof dp); cin >> a1 >> t1 >> a2 >> t2 >> a3 >> t3 >> health >> armor; s1 = a1 - armor, s2 = a2 - armor, s3 = a3 - armor; dp[0] = 0; Max = mx((health + a1 - armor) / (a1 - armor), mx((health + a2 - armor) / (a2 - armor), (health + a3 - armor) / (a3 - armor))); for (int i = 0; i < health; i++) { for (int j = 1; j <= Max; j++) { t = mn(health, i + j * s1 + j * t1 / t2 * s2 + j * t1 / t3 * s3); dp[t] = mn(dp[t], dp[i] + j * t1); t = mn(health, i + j * s2 + j * t2 / t3 * s3 + j * t2 / t1 * s1); dp[t] = mn(dp[t], dp[i] + j * t2); t = mn(health, i + j * s3 + j * t3 / t1 * s1 + j * t3 / t2 * s2); dp[t] = mn(dp[t], dp[i] + j * t3); if (j * t1 >= t2 && j * t1 >= t3) { t = mn(health, i + (j - 1) * s1 + (j * t1 - t2) / t2 * s2 + (j * t1 - t3) / t3 * s3 + (a1 + a2 + a3 - armor)); dp[t] = mn(dp[t], dp[i] + j * t1); } if (j * t2 >= t3 && j * t2 >= t1) { t = mn(health, i + (j - 1) * s2 + (j * t2 - t3) / t3 * s3 + (j * t2 - t1) / t1 * s1 + (a1 + a2 + a3 - armor)); dp[t] = mn(dp[t], dp[i] + j * t2); } if (j * t3 >= t1 && j * t3 >= t2) { t = mn(health, i + (j - 1) * s3 + (j * t3 - t1) / t1 * s1 + (j * t3 - t2) / t2 * s2 + (a1 + a2 + a3 - armor)); dp[t] = mn(dp[t], dp[i] + j * t3); } } } cout << dp[health]; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); sol(); return 0; } ```