跳到正文

个人记录

一些杂七杂八的东西

MoeThm约 6 分钟
原文
文章信息与版本

文章信息

发布
2022年1月21日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 6 分钟
获赞
1

版本

  1. v1当前

优质资源

好东西

背包问题题解

完全背包的理解

多重背包二进制拆分的理解

背包九讲

区间DP

lower_bound和upper_bound

背包超详细讲解

KMP算法解析

详解KMP算法

border与周期(KMP推论)

border与周期(较详细)

线段树 从入门到进阶

线段树详解(原理、实现和运用)

Catalan数

高一数学平面向量与四心结合1

高一数学平面向量与四心结合2

三角形“四心”+与向量的完美结合

高一物理必修二 双星与多星系统

树形DP基础题讲解


合成材料题解

C++
#include <cstdio>
#define r register
long long t[100], a[100], b[100], m[100];
inline long long read() {
    r char ch;
    r bool aa = 0;
    while (ch = getchar(), ch > 57 || ch < 48) ch == '-' ? aa = 1 : 0;
    r long long x = ch ^ 48;
    while (ch = getchar(), ch >= 48 && ch <= 57) x = x * 10 + (ch ^ 48);
    return aa ? -x : x;
}
int main() {
    // freopen("material.in","r",stdin);
    // freopen("material.out","w",stdout);
    r int n = read();
    for (r int i = 2; i <= n; i++) t[i] = read(), a[i] = read(), b[i] = read();  // a[i]个t[i]合成b[i] 个i
    for (r int i = 2; i <= n; i++) m[i] = read();                                // m[i] 为i需要的个数
    for (r int i = n; i >= 2; i--) {
        r long long tmp = m[i] / b[i];  //记录要合成的次数
        (m[i] % b[i]) && (tmp++);       // m[i]%b[i]?tmp++:0;//如果有余说明还要合成一次
        m[t[i]] += tmp * a[i];          //更新m[t[i]]
    }
    return !printf("%lld", m[1]);
}

或者

C++
#include <iostream>
#include <cmath>
using namespace std;
long long t[50], a[50], b[50], m[50];
int i;
void search(int x) {
    if (x == 1)
        return;
    m[t[x]] += m[x] / b[x] * a[x];
    if (m[x] % b[x])
        m[t[x]] += a[x];
    search(x - 1);
}
int main() {
    int n;
    cin >> n;
    for (i = 2; i <= n; i++) cin >> t[i] >> a[i] >> b[i];
    for (i = 2; i <= n; i++) cin >> m[i];
    search(n);
    cout << m[1] << endl;
    return 0;
}

嘿咻

drzo博客

io游戏

原文