<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Everlasting的博客</title><description>博客</description><link>https://blog.everlasting.xin/</link><language>zh_CN</language><item><title>2026_WUST选拔赛Round1_L题题解</title><link>https://blog.everlasting.xin/posts/2026_wust%E9%80%89%E6%8B%94%E8%B5%9Bround1_l%E9%A2%98%E9%A2%98%E8%A7%A3/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/2026_wust%E9%80%89%E6%8B%94%E8%B5%9Bround1_l%E9%A2%98%E9%A2%98%E8%A7%A3/</guid><description>2026_WUST选拔赛Round1_L题题解</description><pubDate>Mon, 15 Jun 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;2026 WUST选拔赛Round1 L题题解&lt;/h1&gt;
&lt;p&gt;原题链接：&lt;a href=&quot;https://ac.nowcoder.com/acm/problem/16033&quot;&gt;Nowcoder&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;题意：&lt;/h2&gt;
&lt;p&gt;在 $1$ 到 $n$ 上有 $n$ 个位置，每个位置放置了一个弹簧，弹簧能将弹球弹到固定的点 $a[i]$ $(1 \leq a[i] \leq n)$ 上。&lt;/p&gt;
&lt;p&gt;接下来要进行 $m$ 个操作：在第 $i$ $(1 \leq i \leq m)$ 个操作中，你需要放置一个拥有无限动力的弹球在 $b[i] \oplus c[i - 1]$ 处，并回答在 $b[i] \oplus c[i - 1]$ 处的弹球个数 $c[i]$ 。&lt;/p&gt;
&lt;p&gt;注意：操作的顺序为：先放入一个弹球，询问当前位置的弹球数量，再所有弹球沿边移动一步。&lt;/p&gt;
&lt;p&gt;已知 $c[0] = 0$ 。给定位置个数 $n$ $(1 \leq n \leq 5e5)$ ，操作数 $m$ $(1 \leq m \leq 5e5)$ 和数组 $a$， $b$。保证所有弹球都会被放置在 $pos$ $(1 \leq pos \leq n)$ 中。&lt;/p&gt;
&lt;h2&gt;思路：&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;转化题意&lt;/p&gt;
&lt;p&gt;由于每个位置的弹球都会在一次操作中从位置 $x$ 被移到 $a[x]$，因此可以将每一个位置看成一个点，并连接一条有向边，形成了由若干个基环树组成的函数图。因此，此题可以转化为：
在由若干个基环树组成的函数图上，支持动态加入弹球，并在线查询某个时刻某个点上的弹球数量。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;非环点&lt;/p&gt;
&lt;p&gt;对于不在环上的点，弹球会不断沿边移动，直到第一次到达&lt;strong&gt;唯一的，且在其所在基环树的环上的点&lt;/strong&gt;为止。对于任意一个基环树来说，每一个非环点都在以&lt;strong&gt;某个唯一的，且在其所在基环树的环上的点&lt;/strong&gt;为根的树上。因此，我们可以建立反图，利用树的结构去维护位置。&lt;/p&gt;
&lt;p&gt;接下来需要维护非环点上弹球的位置。设在第 $t$ 次操作中在非环点 $u$ 放入弹球，在第 $i$ $(t \leq i \leq m)$ 次操作中询问非环点 $v$ ，且这个弹球在点 $v$ 上。利用树的结构，我们可以知道弹球从 $u$ 移动到点 $v$ 所需要的时间为点 $u$ 在树上的深度减去 $v$ 的在树上的深度，设 $dep[x]$ 表示点 $x$ 的深度，即有：$i - t = dep[u] - dep[v]$，变形可以得到：
$$i + dep[v] = t + dep[u]$$&lt;/p&gt;
&lt;p&gt;另外，点 $u$ 一定位于以点 $v$ 为根的子树中。因此，不仅要满足 $i + dep[v] = t + dep[u]$ 的时间条件，也要满足路径条件。可以对每一个树都维护一个 $dfs$ 序，设点 $tin[x]$ 和 $tout[x]$ 分别为点 $x$ 的 $dfs$ 进入时间和点 $x$ 子树内最大的 $dfs$ 进入时间，则需满足：$$tin[v] \leq tin[u] \leq tout[v]$$&lt;/p&gt;
&lt;p&gt;因此，查询非环点 $v$ 时，只需统计满足$i + dep[v] = t + dep[u]$且$tin[u]$ 在 $[tin[v], tout[v]]$ 之间的历史插入点 $u$ 。因此，可以按照 $key$ $(key = t + dep[u])$ 的值进行分类，对于每一个 $key$ 来说，使用对应的平衡树维护其插入点的$dfs$序，并统计 $[tin[v], tout[v]]$ 之间的数目即可。我们可以使用&lt;code&gt;unordered_map&amp;lt;int, ordered_set&amp;lt;array &amp;lt;int, 2&amp;gt; &amp;gt;&lt;/code&gt;进行维护。其中 $key = t + dep[u]$ ，&lt;code&gt;ordered_set&lt;/code&gt;中存储 &lt;code&gt;{tin[u], t}&lt;/code&gt; ，防止同一个点多次插入后仍计算为同一个点。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;环点&lt;/p&gt;
&lt;p&gt;对于环上的点，弹球会不断沿环上的边移动。设在第 $t$ 次操作中在环点 $u$ 放入弹球，环点 $u$ 所在的环的长度为 $len$ ，环点编号为 $pos_i$ 。则在第 $T$ $(t \leq T \leq m)$ 次操作中，弹球会移动到编号为 $pos[v]$ $(pos[v] \equiv pos[u] + (T - t) \pmod {len})$ 上，变形有：
$$pos[u] - t \equiv pos[v] - T \pmod {len}$$&lt;/p&gt;
&lt;p&gt;因此，与非环点类似， $pos[u] - t$ 仍然是一个不变量 $c_id$ ，利用简单数组统计有相同 $c_id$ 的点的数量即可。&lt;/p&gt;
&lt;p&gt;除此之外，环点还需要维护弹球从非环点走到环上的弹球数量。对于每一个在非环点的弹球，可以利用其树的深度来快速算出其进入环点的时间，可以在对应的时间把这些点当作环点加入环内即可。&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;代码：&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
#include &amp;lt;bits/extc++.h&amp;gt;
using namespace std;
using namespace __gnu_pbds;
#define int long long
template &amp;lt;typename T&amp;gt;
using ordered_set = tree&amp;lt;T, null_type, less&amp;lt;T&amp;gt;, rb_tree_tag, tree_order_statistics_node_update&amp;gt;;
using arr2 = array &amp;lt;int, 2&amp;gt;;

void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;
    vector &amp;lt;int&amp;gt; a(n + 1), ind(n + 1);
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; rev(n + 1);

    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; a[i];
        ind[a[i]]++;
        rev[a[i]].push_back(i);
    }

    // 一.建基环树
    // 1.topo判环
    vector &amp;lt;int&amp;gt; removed(n + 1);
    queue &amp;lt;int&amp;gt; q;
    for (int i = 1; i &amp;lt;= n; i++) {
        if (ind[i] == 0) {
            q.push(i);
        }
    }

    while (!q.empty()) {
        auto u = q.front();
        q.pop();
        removed[u] = true;
        int v = a[u];
        if (--ind[v] == 0) q.push(v);
    }

    // 2.建环
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; cycle;
    vector &amp;lt;int&amp;gt; vis(n + 1, 0);
    int id = 0;
    for (int i = 1; i &amp;lt;= n; i++) {
        if (removed[i] || vis[i]) continue;
        vector &amp;lt;int&amp;gt; cyc;
        int u = i;
        while (!vis[u]) {
            vis[u] = 1;
            cyc.push_back(u);
            u = a[u];
        }
        cycle.push_back(cyc);
    }

    // 3.初始化树的信息
    vector &amp;lt;int&amp;gt; comp(n + 1), pos(n + 1), dep(n + 1), root(n + 1);
    int sum_cyc = cycle.size();

    for (int id = 0; id &amp;lt; sum_cyc; id++) {
        for (int i = 0; i &amp;lt; cycle[id].size(); i++) {
            int u = cycle[id][i];
            comp[u] = id;
            pos[u] = i;
            dep[u] = 0;
            root[u] = u;
        }
    }

    // 4.建反树
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; e(n + 1);
    for (int u = 1; u &amp;lt;= n; u++) {
        for (auto v : rev[u]) {
            if (removed[v]) {
                e[u].push_back(v);
            }
        }
    }

    // 5.求dfs序
    vector &amp;lt;int&amp;gt; tin(n + 1), tout(n + 1);
    int time = 0;

    auto dfs = [&amp;amp;] (auto self, int u) -&amp;gt; void {
        tin[u] = ++time;
        for (auto v : e[u]) {
            comp[v] = comp[u];
            root[v] = root[u];
            dep[v] = dep[u] + 1;
            self(self, v);
        }
        tout[u] = time;
    };

    for (auto &amp;amp;cyc : cycle) {
        for (auto r : cyc) {
            dfs(dfs, r);
        }
    }

    // 二.计算答案

    // 1.初始化
    int m;
    cin &amp;gt;&amp;gt; m;
    vector &amp;lt;int&amp;gt; len(sum_cyc);
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; cyc_info(sum_cyc);
    for (int id = 0; id &amp;lt; sum_cyc; id++) {
        len[id] = cycle[id].size();
        cyc_info[id].assign(len[id], 0);
    }

    vector &amp;lt;vector &amp;lt;arr2&amp;gt; &amp;gt; update(m + 1);
    unordered_map &amp;lt;int, ordered_set&amp;lt;arr2&amp;gt; &amp;gt; mp;
    mp.reserve(m * 2 + 10);

    int pre = 0;

    for (int i = 1; i &amp;lt;= m; i++) {
        for (auto [id, c_id] : update[i]) {
            cyc_info[id][c_id]++;
        }
        int x;
        cin &amp;gt;&amp;gt; x;
        x = (x ^ pre);

        // 2.插入
        if (!removed[x]) {
            int id = comp[x];
            int c_id = ((pos[x] - i) % len[id] + len[id]) % len[id];
            cyc_info[id][c_id]++;
        }else {
            int key = i + dep[x];
            mp[key].insert({tin[x], i});
            int T = i + dep[x];
            if (T &amp;lt;= m) {
                int id = comp[x];
                int c_id = ((pos[root[x]] - T) % len[id] + len[id]) % len[id];
                update[T].push_back({id, c_id});
            }
        }

        // 3.查询
        int res = 0;
        if (!removed[x]) {
            int id = comp[x];
            int c_id = ((pos[x] - i) % len[id] + len[id]) % len[id];
            res = cyc_info[id][c_id];
        }else {
            int key = i + dep[x];
            auto it = mp.find(key);
            if (it != mp.end()) {
                auto &amp;amp;st = it-&amp;gt;second;
                res = st.order_of_key({tout[x] + 1, -1}) - st.order_of_key({tin[x], -1});
            }
        }

        cout &amp;lt;&amp;lt; res &amp;lt;&amp;lt; &apos;\n&apos;;
        pre = res;
    }
}

int32_t main ()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
} 
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>Atcoder Beginner Contest 459 F题题解</title><link>https://blog.everlasting.xin/posts/abc459f%E9%A2%98%E8%A7%A3/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/abc459f%E9%A2%98%E8%A7%A3/</guid><description>Atcoder Beginner Contest 459 F题题解</description><pubDate>Sun, 24 May 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;Atcoder Beginner Contest 459 F题题解&lt;/h1&gt;
&lt;h2&gt;题意：&lt;/h2&gt;
&lt;p&gt;给你一个长度为 $N$ 的非负整数序列 $A = (A_1, A_2, \ldots, A_N)$ 。&lt;/p&gt;
&lt;p&gt;你可以对 $A$ 执行下列操作零次或多次：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;选择一个有 $1 \le i \le N - 1$ 的整数 $i$ ，将 $A_i$ 减少 $1$ ，并将 $A_{i+1}$ 增加 $1$ 。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;求使 $A$ 严格递增所需的最小运算次数。&lt;/p&gt;
&lt;p&gt;可以证明答案小于 $2^{63}$ 。&lt;/p&gt;
&lt;p&gt;给你 $T$ 个测试用例，请逐个求解。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$1 \le T \le 3 \times 10^5$&lt;/li&gt;
&lt;li&gt;$1 \le N \le 2 \times 10^5$&lt;/li&gt;
&lt;li&gt;$0 \le A_i \le 10^9$&lt;/li&gt;
&lt;li&gt;所有测试用例中 $N$ 的总和最多为 $6 \times 10^5$ 。&lt;/li&gt;
&lt;li&gt;所有输入值均为整数。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;思路：&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;将求严格递增的序列 $B$ 转换为求非递减的序列 $B$ 。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;将原序列 $A$ 的每一项转换为 $a_i - i$ 即可。设序列 $B$ 为 $b_i = a_i - i$， 则 $b_i - b_{i - 1} = a_i - a_{i - 1} - (i - (i - 1))$， 即 $b_i - b_{i - 1} = a_i - a_{i - 1} - 1$，这天然满足严格递增的条件，因此求非递减的序列即可。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;将每个数看成一个块，若左边的块的最右端的值大于右边的块的最左端的值，将两个块合并成一个块。在处理每一个块时，需要将块中的值尽可能平均放。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;开始时每个块中非递减严格成立。在处理每一个块时，若遇到左边的值的最右端的值大于右边的块的最左端的值，需要合并两个块。此时的情况是需要将左边的值转移至右边，我们就可以尽可能贪心的让左边的值少减一点，即将左端的值最大化，右端的值最小化。在处理每一个块时，我们只需要维护其块内的值的总和和块的长度即可。从左到右遍历块，最后形成一个满足条件的连续的若干个块。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;设原序列为 $A$， 最终序列为 $B$，则答案 $ans$ 为： $ans = \sum_{i = 1}^{n} (prefixA_i - prefixB_i)$&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;设序列 $X$，令 $x_i$ 为从第 $i$ 个点到第 $i + 1$ 个点被操作了多少次$(1 \leq i \leq n - 1)$，则 $b_i = a_i + x_{i - 1} - x_i$。易得 $x_1 = a_1 - b_1$，则 $x_2 = a_2 - b_2 + x_1$，即 $x_2 - x_1 = a_2 - b_2$，即有：$x_2 = (a_2 - b_2) + (a_1 - b_1)$，所以有：$$x_i = prefixA_i - prefixB_i$$。答案便是 $\sum_{i = 1}^{n}x_i$&lt;/p&gt;
&lt;h2&gt;代码：&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
#define int long long

struct node {
    int len, sum;
    node operator + (const node &amp;amp;other) const {
        return node{other.len + len, other.sum + sum};
    }
};

int Floor (int a, int b) {
    if (a &amp;gt;= 0) return a / b;
    return -((-a + b - 1) / b);

}

int Ceil (int a, int b) {
    return -Floor(-a, b);
}

void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;
    vector &amp;lt;int&amp;gt; v(n + 1);
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; v[i];
        v[i] -= i;
    }

    vector &amp;lt;node&amp;gt; st;
    for (int i = 1; i &amp;lt;= n; i++) {
        st.push_back({1, v[i]});
        while (st.size() &amp;gt;= 2) {
            node s = st.back();
            node t = st[st.size() - 2];
            int smn = Floor(s.sum, s.len);
            int tmx = Ceil(t.sum, t.len);
            if (smn &amp;lt; tmx) {
                st.pop_back();
                st.pop_back();
                st.push_back({s + t});
            }else {
                break;
            }
        }
    }

    vector &amp;lt;int&amp;gt; f(n + 1);
    int pos = 1;

    for (auto x : st) {
        int mn = Floor(x.sum, x.len);
        int cmx = x.sum - mn * x.len;
        int cmn = x.len - cmx;
        for (int i = 1; i &amp;lt;= cmn; i++) {
            f[pos++] = mn;
        }
        for (int i = 1; i &amp;lt;= cmx; i++) {
            f[pos++] = mn + 1;
        }
    }

    int ans = 0;
    int pv = 0, pf = 0;
    for (int i = 1; i &amp;lt;= n - 1; i++) {
        pv += v[i];
        pf += f[i];
        ans += pv - pf;
    }

    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}   
    
int32_t main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
} 
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>CF1463B题解</title><link>https://blog.everlasting.xin/posts/cf1463b%E9%A2%98%E8%A7%A3/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/cf1463b%E9%A2%98%E8%A7%A3/</guid><description>CF1463B题解</description><pubDate>Fri, 22 May 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;CF1463B题解&lt;/h1&gt;
&lt;h2&gt;题意：&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://codeforces.com/problemset/problem/1463/B&quot;&gt;题目链接&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;给你一个数组 $[a_1, a_2, \dots, a_n]$ ，其中有 $1 \le a_i \le 10^9$ 。设 $S$ 是数组 $a$ 中所有元素的和。&lt;/p&gt;
&lt;p&gt;如果 $n$ 个整数组成的数组 $b$ &lt;strong&gt;漂亮&lt;/strong&gt;，那么我们就把这个数组称为 $b$ ：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;从 $1$ 到 $n$ 的每个 $i$ 都是 $1 \le b_i \le 10^9$ ；&lt;/li&gt;
&lt;li&gt;对于数组 $(b_i, b_{i + 1})$ 中的每一对相邻整数，要么是 $b_i$ 除以 $b_{i + 1}$ ，要么是 $b_{i + 1}$ 除以 $b_i$ （或者两者都是(或两者）；&lt;/li&gt;
&lt;li&gt;$2 \sum \limits_{i = 1}^{n} |a_i - b_i| \le S$ .&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;lt;!-- more --&amp;gt;&lt;/p&gt;
&lt;h2&gt;思路：&lt;/h2&gt;
&lt;p&gt;对于构造合法解的题目，我们可以先想什么能够稳定的构造相邻整除的数组。再结合$2 \sum \limits_{i = 1}^{n} |a_i - b_i| \le S$，不难推得$$ \frac{1}{2}a_i \leq b_i \leq \frac{3}{2}a_i$$
注意到存在$ \frac{1}{2}a_i$，可以想到把每一个$b_i$都设置成小于等于$b_i$的最大的$2$的幂。即有：$0 \leq a_i - b_i &amp;lt; \frac{1}{2}a_i$
求和即有：$$\sum \limits_{i = 1}^{n} |a_i - b_i| \leq \frac{1}{2}S$$
满足要求&lt;/p&gt;
&lt;h2&gt;代码：&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;
    for (int i = 1; i &amp;lt;= n; i++) {
        int t;
        cin &amp;gt;&amp;gt; t;
        cout &amp;lt;&amp;lt; (1LL &amp;lt;&amp;lt; __lg(t)) &amp;lt;&amp;lt; &quot; \n&quot;[i == n];
    }
}   
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>关于&lt;bits/extc++.h&gt;在windows上编译失败的解决方案</title><link>https://blog.everlasting.xin/posts/fixed_extch_problem/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/fixed_extch_problem/</guid><description>记录&lt;bits/extc++.h&gt;在windows上编译失败的解决方案</description><pubDate>Wed, 20 May 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;Windows 下给 MinGW 手动补齐 &lt;code&gt;iconv.h&lt;/code&gt; 环境教程&lt;/h1&gt;
&lt;h2&gt;1. 问题背景&lt;/h2&gt;
&lt;p&gt;在 Windows 下使用 MinGW / WinLibs 编译 C++ 代码时，如果包含：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/extc++.h&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;可能会遇到类似错误：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;fatal error: iconv.h: No such file or directory
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;错误链大概是：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;bits/extc++.h&amp;gt;
    ↓
&amp;lt;ext/codecvt_specializations.h&amp;gt;
    ↓
&amp;lt;iconv.h&amp;gt;
    ↓
找不到 iconv.h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这个问题的本质不是 C++ 代码写错了，而是当前 MinGW 环境里缺少 &lt;code&gt;libiconv&lt;/code&gt; 相关的头文件和库文件。&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;2. 适用环境&lt;/h2&gt;
&lt;p&gt;本教程适用于 Windows 下手动配置 MinGW / WinLibs 环境，并且不想安装完整 MSYS2，只想补齐 &lt;code&gt;iconv.h&lt;/code&gt; 相关文件的情况。&lt;/p&gt;
&lt;p&gt;可以通过下面命令查看自己的编译器信息：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;g++ -v
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;重点观察输出中的关键词，比如：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;x86_64-w64-mingw32
ucrt
mingw64
clang64
i686
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;根据自己的环境选择对应的 &lt;code&gt;libiconv&lt;/code&gt; 包：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;你的环境&lt;/th&gt;
&lt;th&gt;关键词&lt;/th&gt;
&lt;th&gt;应下载的包&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;普通 64 位 MinGW / MSVCRT&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x86_64-w64-mingw32&lt;/code&gt;、&lt;code&gt;mingw64&lt;/code&gt;、没有 &lt;code&gt;ucrt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-x86_64-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;UCRT64&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ucrt&lt;/code&gt;、&lt;code&gt;ucrt64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-ucrt-x86_64-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;CLANG64&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;clang64&lt;/code&gt;、&lt;code&gt;clang-x86_64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-clang-x86_64-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;32 位 MinGW&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;i686&lt;/code&gt;、&lt;code&gt;mingw32&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-i686-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;例如，如果 &lt;code&gt;g++ -v&lt;/code&gt; 输出中有类似：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;MinGW-W64 x86_64-ucrt-posix-seh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;说明你使用的是 &lt;strong&gt;UCRT64 版本&lt;/strong&gt;，这种情况下应该下载：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw-w64-ucrt-x86_64-libiconv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;如果输出中没有 &lt;code&gt;ucrt&lt;/code&gt;，而是普通的 64 位 MinGW 环境，一般应该下载：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw-w64-x86_64-libiconv
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;3. 下载 libiconv 包&lt;/h2&gt;
&lt;p&gt;进入 MSYS2 Packages 页面，下载自己环境对应的 &lt;code&gt;libiconv&lt;/code&gt; 包。&lt;/p&gt;
&lt;p&gt;MSYS2 Packages 搜索页：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;https://packages.msys2.org/search?t=binpkg&amp;amp;q=libiconv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;也可以根据自己的环境直接进入对应页面：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;你的环境&lt;/th&gt;
&lt;th&gt;应下载的包&lt;/th&gt;
&lt;th&gt;下载页面&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;普通 64 位 MinGW / MSVCRT&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-x86_64-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://packages.msys2.org/package/mingw-w64-x86_64-libiconv&quot;&gt;https://packages.msys2.org/package/mingw-w64-x86_64-libiconv&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;UCRT64&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-ucrt-x86_64-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://packages.msys2.org/package/mingw-w64-ucrt-x86_64-libiconv&quot;&gt;https://packages.msys2.org/package/mingw-w64-ucrt-x86_64-libiconv&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;CLANG64&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-clang-x86_64-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://packages.msys2.org/package/mingw-w64-clang-x86_64-libiconv&quot;&gt;https://packages.msys2.org/package/mingw-w64-clang-x86_64-libiconv&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;32 位 MinGW&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw-w64-i686-libiconv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://packages.msys2.org/package/mingw-w64-i686-libiconv&quot;&gt;https://packages.msys2.org/package/mingw-w64-i686-libiconv&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;进入对应页面后，找到页面中的 &lt;code&gt;File&lt;/code&gt; 一栏，下载 &lt;code&gt;.pkg.tar.zst&lt;/code&gt; 文件。&lt;/p&gt;
&lt;p&gt;例如 UCRT64 环境的页面中，文件名通常类似:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw-w64-ucrt-x86_64-libiconv-1.19-1-any.pkg.tar.zst
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;普通 64 位 MinGW 环境的文件名通常类似：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw-w64-x86_64-libiconv-1.19-1-any.pkg.tar.zst
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;注意：版本号可能会随着 MSYS2 更新而变化，所以实际下载时以页面中的 &lt;code&gt;File&lt;/code&gt; 一栏为准。&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;4. 解压 &lt;code&gt;.pkg.tar.zst&lt;/code&gt; 文件&lt;/h2&gt;
&lt;p&gt;下载后你会得到一个类似这样的文件：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw-w64-ucrt-x86_64-libiconv-1.19-1-any.pkg.tar.zst
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;解压展开后一般会看到一个环境目录，例如：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ucrt64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;或者：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;再展开后应该有：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;环境目录\bin
环境目录\include
环境目录\lib
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;例如 UCRT64 包中通常是：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ucrt64\bin
ucrt64\include
ucrt64\lib
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;普通 MINGW64 包中通常是：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw64\bin
mingw64\include
mingw64\lib
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;5. 复制文件到你的 MinGW 目录&lt;/h2&gt;
&lt;p&gt;假设你的 MinGW / WinLibs GCC 安装目录是：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;那么要把解压出来的环境目录中的文件复制到这个目录下。&lt;/p&gt;
&lt;p&gt;例如你解压出来的是：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ucrt64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;就把 &lt;code&gt;ucrt64&lt;/code&gt; 里面的 &lt;code&gt;include&lt;/code&gt;、&lt;code&gt;lib&lt;/code&gt;、&lt;code&gt;bin&lt;/code&gt; 中的相关文件复制到：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\include
D:\gcc-14.2.0\mingw64\lib
D:\gcc-14.2.0\mingw64\bin
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;如果你解压出来的是：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mingw64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;也是同理，把里面对应的文件复制到你自己的 MinGW 安装目录。&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;5.1 复制 include 文件&lt;/h2&gt;
&lt;p&gt;从解压目录：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;环境目录\include
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;复制以下文件：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;iconv.h
libcharset.h
localcharset.h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;到你的 MinGW include 目录：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\include
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;也就是最终应该存在：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\include\iconv.h
D:\gcc-14.2.0\mingw64\include\libcharset.h
D:\gcc-14.2.0\mingw64\include\localcharset.h
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;5.2 复制 lib 文件&lt;/h2&gt;
&lt;p&gt;从解压目录：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;环境目录\lib
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;复制以下文件：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;libiconv.a
libiconv.dll.a
libcharset.a
libcharset.dll.a
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;到你的 MinGW lib 目录：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\lib
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;最终应该存在：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\lib\libiconv.a
D:\gcc-14.2.0\mingw64\lib\libiconv.dll.a
D:\gcc-14.2.0\mingw64\lib\libcharset.a
D:\gcc-14.2.0\mingw64\lib\libcharset.dll.a
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;5.3 复制 bin 文件&lt;/h2&gt;
&lt;p&gt;从解压目录：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;环境目录\bin
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;复制以下文件：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;libiconv-2.dll
libcharset-1.dll
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;到你的 MinGW bin 目录：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\bin
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;最终应该存在：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;D:\gcc-14.2.0\mingw64\bin\libiconv-2.dll
D:\gcc-14.2.0\mingw64\bin\libcharset-1.dll
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;p&gt;复制完后即可正常编译运行了&lt;/p&gt;
</content:encoded></item><item><title>华中农业大学第十五届程序设计竞赛游记及部分题解</title><link>https://blog.everlasting.xin/posts/%E5%8D%8E%E4%B8%AD%E5%86%9C%E4%B8%9A%E5%A4%A7%E5%AD%A6%E7%AC%AC%E5%8D%81%E4%BA%94%E5%B1%8A%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E7%AB%9E%E8%B5%9B%E6%B8%B8%E8%AE%B0%E9%A2%98%E8%A7%A3/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/%E5%8D%8E%E4%B8%AD%E5%86%9C%E4%B8%9A%E5%A4%A7%E5%AD%A6%E7%AC%AC%E5%8D%81%E4%BA%94%E5%B1%8A%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E7%AB%9E%E8%B5%9B%E6%B8%B8%E8%AE%B0%E9%A2%98%E8%A7%A3/</guid><description>记录我参加华中农业大学第十五届程序设计竞赛的经历，以及部分题目的题解和代码。</description><pubDate>Mon, 06 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;华中农业大学第十五届程序设计竞赛游记及部分题解&lt;/h1&gt;
&lt;h2&gt;游记&lt;/h2&gt;
&lt;p&gt;今年第二场线下比赛，赛前几天一直晕晕的，虽然但是，最后还是以六题拿了铜牌，但之后也要加强一些算法的训练了，有些算法的不熟悉导致了很多题目看着没思路，赛后发现实际上思路其实并不是特别困难。赛时快速切了I，D两道签到后，就被E题卡死，直到封榜后没招了，E题写了一位一位的向上模拟侥幸通过~~（实际上是因为模拟写假了且在第一步特判时实际上就把题目写完了所以侥幸过了）&lt;s&gt;。在过E前，过了G，F两题，G因为自己迟迟没有过E心态爆炸而wa了6发，F看出二叉树遍历后写得还算顺利。过了E之后，就去写了L，感觉L还算简单，感觉题解写复杂了。
剩下能写的B和J感觉是因为自己对状压dp和st倍增的不熟悉而没有能写的思路，C看没多少人过也没细看，实际上思路还算清晰吧，感觉这次比赛有些可惜。之后得加训了&lt;/s&gt;（上次就说要加训来着）~~。&lt;/p&gt;
&lt;h2&gt;题解&lt;/h2&gt;
&lt;h3&gt;I&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;要买$n$杯奶茶，买一杯需要$a$元，买两杯需要$b$元，问最少需要多少钱能恰好买到$n$杯奶茶？&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
	i64 n, a, b;
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b;
	if (2 * a &amp;lt;= b) {
		i64 ans = n * a;
		cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
	}else {
		i64 t = n / 2 * b;
		if (n &amp;amp; 1) {
			t += a;
		}
		cout &amp;lt;&amp;lt; t &amp;lt;&amp;lt; &apos;\n&apos;;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;D&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定整数$c$ $(2 \leq c \leq 1e9)$，需要找到两个正整数$a$和$b$,满足$a + b == c$，且使$lcm(a, b)$最大。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;对于奇数，直接取$\lfloor n / 2 \rfloor$和$\lceil n / 2 \rceil$即可。
对于偶数，在$n / 2$的基础上往下，往上找到$lcm(l, r) == l \times r$的数即可。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
	i64 n;
	cin &amp;gt;&amp;gt; n;
	if (n &amp;amp; 1) {
		i64 t1 = n / 2;
		i64 t2 = n - n / 2;
		i64 ans = t1 * t2;
		cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
	}else {
		i64 l = n / 2, r = n / 2;
		while (lcm(l, r) != l * r) {
			l--;
			r++;
		}
		i64 ans = lcm(l, r);
		cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;G&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定$n$个魔法飞弹，第$i$枚飞弹对应第$i$个哥布林，给定每个飞弹的穿透力$a_i$和伤害$c_i$，和每个哥布林的防御力$b_i$。当且仅当$a_i \geq b_i$时飞弹才会对哥布林造成伤害。现在有$q$次独立的询问，每一次你有一次可以将任意一枚飞弹的穿透力修改为$X$的机会，求每一次最多能对哥布林造成多少总伤害？&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;我们可以预先处理出不修改穿透力的总伤害，再在剩余的未能造成伤害的飞弹里面先按需要的穿透力，即哥布林的防御力排序，再维护一个前缀数组，能够快速求出能把一个穿透力修改为$X$所能多造成的伤害。在处理询问时，仅需在前缀数组中二分查找即可。&lt;/p&gt;
&lt;p&gt;时间复杂度：$O((n + q)\log n)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
	int n, q;
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; q;
	vector &amp;lt;array &amp;lt;i64, 3&amp;gt; &amp;gt; v(n + 1);
	for (int i = 1; i &amp;lt;= n; i++) {
		cin &amp;gt;&amp;gt; v[i][0];
	}
	for (int i = 1; i &amp;lt;= n; i++) {
		cin &amp;gt;&amp;gt; v[i][1];
	}
	for (int i = 1; i &amp;lt;= n; i++) {
		cin &amp;gt;&amp;gt; v[i][2];
	}
	
	i64 res = 0;
	vector &amp;lt;array &amp;lt;i64, 2&amp;gt; &amp;gt; a;
	a.reserve(n + 1);
	for (int i = 1; i &amp;lt;= n; i++) {
		if (v[i][0] &amp;gt;= v[i][1]) {
			res += v[i][2];
		}else {
			a.push_back({v[i][1], v[i][2]});
		}
	}
	
	sort(a.begin(), a.end(), [] (auto aa, auto bb) {
		if (aa[0] != bb[0]) {
			return aa[0] &amp;lt; bb[0];
		}else {
			return aa[1] &amp;gt; bb[1];
		}
	});
	
	i64 m = a.size();
	vector &amp;lt;i64&amp;gt; pre(m + 1);
	if (!a.empty()) pre[0] = a[0][1];
	for (int i = 1; i &amp;lt; m; i++) {
		pre[i] = max(pre[i - 1], a[i][1]);
	}
    
	while (q--) {
		i64 t;
		cin &amp;gt;&amp;gt; t;
		if (a.empty()) {
			cout &amp;lt;&amp;lt; res &amp;lt;&amp;lt; &apos;\n&apos;;
			continue;
		}
		if (!a.empty() &amp;amp;&amp;amp; t &amp;lt; a[0][0]) {
			cout &amp;lt;&amp;lt; res &amp;lt;&amp;lt; &apos;\n&apos;;
			continue;
		}
		int l = 0, r = m - 1;
		while (l &amp;lt;= r) {
			int mid = (l + r) / 2;
			if (a[mid][0] &amp;lt;= t) {
				l = mid + 1;
			}else {
				r = mid - 1;
			}
		}
		cout &amp;lt;&amp;lt; res + pre[r] &amp;lt;&amp;lt; &apos;\n&apos;;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;F&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定一个合法的括号序列$s$，按照左括号的顺序对所有括号对进行从$1$到$n$的编号，对于编号为$p$的括号对，若其左括号后仍为左括号，将下一个左括号的编号$l$作为$p$的左孩子，若其右括号后为左括号，将下一个左括号的编号$r$作为$p$的右孩子。现给出二叉树结构，构造出原来的合法括号序列$s$。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;手玩样例后不难发现，对二叉树进行先序遍历即可。
时间复杂度：$O(n)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
	int n;
	cin &amp;gt;&amp;gt; n;
	vector &amp;lt;array &amp;lt;int, 2&amp;gt; &amp;gt; v(n + 1);
	for (int i = 1; i &amp;lt;= n; i++) {
		cin &amp;gt;&amp;gt; v[i][0] &amp;gt;&amp;gt; v[i][1];
	}

	vector &amp;lt;int&amp;gt; ans;
	auto dfs = [&amp;amp;] (auto self, int fa, int u) -&amp;gt; void {
		ans.push_back(u);
		if (v[u][0] != 0) self(self, u, v[u][0]);
		ans.push_back(u);
		if (v[u][1] != 0) self(self, u, v[u][1]);
	};
	dfs(dfs, 0, 1);
	
	vector &amp;lt;int&amp;gt; cnt(n + 1);
	string s;
	for (auto x : ans) {
		if (cnt[x] == 0) {
			s.push_back(&apos;(&apos;);
			cnt[x]++;
		}else {
			s.push_back(&apos;)&apos;);
		}
	}
	
	cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; &apos;\n&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;E&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定一个正整数$x$ $(1 \leq x \leq 1e12)$，询问是否能找到另一个正整数$k$，使得$x \times k$在十进制中每一个数位上都是$9$？&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;&lt;s&gt;(大胆猜测个位上不能是偶数或5)&lt;/s&gt;
实际上仅需判断$gcd(10, x) = 1$是否成立即可。即$x$不能存在质因子$2$和$5$。
时间复杂度：$O(1)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
	i64 n;
	cin &amp;gt;&amp;gt; n;
    i64 t = n % 10;
    if (t == 1 || t == 3 || t == 7 || t == 9) {
        cout &amp;lt;&amp;lt; &quot;YES\n&quot;;
    }else {
        cout &amp;lt;&amp;lt; &quot;NO\n&quot;;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;L&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定一个大小为$n \times m$的矩阵停车场，每个车位要么是空地（用 . 表示），要么停着一辆固定方向行驶的汽车，方向为：U(上)，D(下)，L(左)，R(右)。若所有车都能够驶离停车场，按顺序输出离开车辆的坐标，否则输出-1。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;简单模拟即可。分别从上到下寻找可以离开停车场的&apos;U&apos;，从下到上寻找可以离开的&apos;D&apos;，从左到右寻找可以离开的&apos;L&apos; ,从右到左寻找可以离开的&apos;R&apos;，依次记录能够离开的车即可。将U, D, L, R记为一轮寻找。若在一轮寻找中没有车能从成功离开且还有车剩余，输出-1即可。
时间复杂度：$O(4 \times n \times m)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
	int n, m;
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
	vector &amp;lt;vector &amp;lt;char&amp;gt; &amp;gt; v(n + 1, vector &amp;lt;char&amp;gt; (m + 1));
	int cnt = 0;
	for (int i = 1; i &amp;lt;= n; i++) {
		for (int j = 1; j &amp;lt;= m; j++) {
			cin &amp;gt;&amp;gt; v[i][j];
			if (v[i][j] != &apos;.&apos;) cnt++;
		} 
	}
	
	vector &amp;lt;array &amp;lt;int, 2&amp;gt; &amp;gt; ans;
	ans.reserve(cnt + 1);

	vector &amp;lt;int&amp;gt; v1(m + 1, 1);//u
	vector &amp;lt;int&amp;gt; v2(m + 1, n);//d
	vector &amp;lt;int&amp;gt; v3(n + 1, 1);//l
	vector &amp;lt;int&amp;gt; v4(n + 1, m);//r	
	
	int pre = cnt;
	while (cnt &amp;gt; 0) {
		for (int j = 1; j &amp;lt;= m; j++) {
			int i = v1[j];
			while (i &amp;lt;= n &amp;amp;&amp;amp; (v[i][j] == &apos;U&apos; || v[i][j] == &apos;.&apos;)) {
				if (v[i][j] == &apos;U&apos;) {
					ans.push_back({i, j});
					cnt--;
					v[i][j] = &apos;.&apos;;
				}
				i++;
			}
			v1[j] = i;
		}
		
		for (int j = 1; j &amp;lt;= m; j++) {
			int i = v2[j];
			while (i &amp;gt;= 1 &amp;amp;&amp;amp; (v[i][j] == &apos;D&apos; || v[i][j] == &apos;.&apos;)) {
				if (v[i][j] == &apos;D&apos;) {
					ans.push_back({i, j});
					cnt--;
					v[i][j] = &apos;.&apos;;
				}
				i--;
			}
			v2[j] = i;
		}
		
		for (int i = 1; i &amp;lt;= n; i++) {
			int j = v3[i];
			while (j &amp;lt;= m &amp;amp;&amp;amp; (v[i][j] == &apos;L&apos; || v[i][j] == &apos;.&apos;)) {
				if (v[i][j] == &apos;L&apos;) {
					ans.push_back({i, j});
					cnt--;
					v[i][j] = &apos;.&apos;;
				}
				j++;
			}
			v3[i] = j;
		}
		
		for (int i = 1; i &amp;lt;= n; i++) {
			int j = v4[i];
			while (j &amp;gt;= 1 &amp;amp;&amp;amp; (v[i][j] == &apos;R&apos; || v[i][j] == &apos;.&apos;)) {
				if (v[i][j] == &apos;R&apos;) {
					ans.push_back({i, j});
					cnt--;
					v[i][j] = &apos;.&apos;;
				}
				j--;
			}
			v4[i] = j;
		}
		
		if (pre == cnt) {
			cout &amp;lt;&amp;lt; -1 &amp;lt;&amp;lt; &apos;\n&apos;;
			return;
		}
		
		pre = cnt;
	}

	for (auto [x, y] : ans) {
		cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &apos;\n&apos;;
	}
	
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;J&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定一个以$1$为根，包含$n$ $(1 \leq n \leq 1e5)$个节点的树，每个节点$i$有一个初始权值$m_i$ $(1 \leq m_i \leq 1e9)$，且对于任意非根节点$x$，其权值不会超过其父节点的权值。
现给出$q$ $(1 \leq q \leq 1e5)$次操作。
第一种操作中给出节点$u$和权值$w$ $(1 \leq w \leq 1e9)$，需要找出第一个权值至少为$w$的节点编号，若找不到则输出-1.
第二种操作中给出节点$x$和权值$v$ $(-1e9 \leq w \leq 1e9)$，需要判断给节点$x$的权值加上$v$后其权值是否超过其父节点的权值或小于其叶节点的权值，若超过其父节点的权值或小于其子节点的权值则修改失败，反之修改成功，并修改权值。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;对于第一种操作，可以用st倍增快速查询，找到最后一个权值小于$w$的节点输出其父节点即可。
对于第二种操作，可以使用multiset，对每个节点存下其子节点的权值，将修改后的权值与父节点的权值和最大的子节点的权值比较即可。
时间复杂度：$O((n + q) \times \log n)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;const int m = 20;

void solve ()
{
    int n, q;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; q;
    vector &amp;lt;i64&amp;gt; val(n + 1);
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; val[i];
    }
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; e(n + 1);
    for (int i = 1; i &amp;lt; n; i++) {
        int u, v;
        cin &amp;gt;&amp;gt; u &amp;gt;&amp;gt; v;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    vector &amp;lt;int&amp;gt; fa(n + 1);
    vector &amp;lt;int&amp;gt; order;
    order.reserve(n + 1);
    fa[1] = 0;
    
    auto dfs = [&amp;amp;] (auto self, int f, int u) -&amp;gt; void {
        order.push_back(u);
        fa[u] = f;
        for (auto v : e[u]) {
            if (v == f) continue;
            self(self, u, v);
        }
    };
    dfs(dfs, 0, 1);

    vector &amp;lt;array &amp;lt;int, m&amp;gt; &amp;gt; st(n + 1);
    for (auto u : order) {
        st[u].fill(0);
        st[u][0] = fa[u];
    }
    for (int k = 1; k &amp;lt; m; k++) {
        for (int i = 1; i &amp;lt;= n; i++) {
            st[i][k] = st[st[i][k - 1]][k - 1];
        }
    }

    vector &amp;lt;multiset &amp;lt;i64&amp;gt; &amp;gt; a(n + 1);
    for (int i = 2; i &amp;lt;= n; i++) {
        a[fa[i]].insert(val[i]);
    }

    while (q--) {
        int op;
        cin &amp;gt;&amp;gt; op;
        if (op == 1) {
            int u;
            i64 w;
            cin &amp;gt;&amp;gt; u &amp;gt;&amp;gt; w;
            if (val[u] &amp;gt;= w) {
                cout &amp;lt;&amp;lt; u &amp;lt;&amp;lt; &apos;\n&apos;;
                continue;
            }
            int cur = u;
            for (int k = m - 1; k &amp;gt;= 0; k--) {
                int t = st[cur][k];
                if (t != 0 &amp;amp;&amp;amp; val[t] &amp;lt; w) {
                    cur = t;
                }
            }
            if (fa[cur] == 0) {
                cout &amp;lt;&amp;lt; -1 &amp;lt;&amp;lt; &apos;\n&apos;;
            }else {
                cout &amp;lt;&amp;lt; fa[cur] &amp;lt;&amp;lt; &apos;\n&apos;;
            }
        }else {
            int x;
            i64 v;
            cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; v;
            bool ok = true;
            if (x != 1 &amp;amp;&amp;amp; v + val[x] &amp;gt; val[fa[x]]) {
                ok = false;
            }
            if (ok &amp;amp;&amp;amp; !a[x].empty()) {
                i64 mx = *a[x].rbegin();
                if (v + val[x] &amp;lt; mx) {
                    ok = false;
                }
            }
            if (!ok) {
                cout &amp;lt;&amp;lt; &quot;FAILED\n&quot;;
                continue;
            }
            if (x != 1) {
                a[fa[x]].erase(a[fa[x]].find(val[x]));
                a[fa[x]].insert(v + val[x]);
            }
            val[x] += v;
            cout &amp;lt;&amp;lt; &quot;SUCCESS\n&quot;;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;B&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;有$n$ $(1 \leq n \leq 20)$个连续的公交车座位，编号从$1$到$n$，其中有$m$ $(0 \leq m \leq n)$个座位是损坏的。Alice和Bob轮流安排乘客入座，Alice先手，并希望入座的乘客尽量多，Bob希望入座的乘客尽量少。给定距离$k$，要求任意两名乘客的间距至少大于$k$ $(1 \leq k \leq 20)$。以字符串的形式输出最终可能的座位状态。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;注意到$n \leq 20$，考虑状压dp。设$dp[mask]$表示座位占有情况为$mask$时，最优的总入座人数。提前用dfs处理好每一个状态的最优总入座人数：若轮到Alice，其目标为最大化最终人数，枚举每一个合法的$i$，即：$dp[mask] = max , dp[mask \mid (1 \ll i)]$，若轮到Bob，其目标为最小化最终人数，枚举每一个合法的$i$，即：$dp[mask] = min , dp[mask \mid (1 \ll i)]$。
接下来需要还原最终方案：可以从$mask = 0$开始正向模拟，对于$mask$状态，枚举所有合法的$i$，寻找某个$dp[mask \mid (1 \ll i)] = dp[mask]$，并将$mask$更新为$mask \mid (1 \ll i)$后继续查找即可。
时间复杂度：$O(n \times 2^n)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    int n, k, m;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k &amp;gt;&amp;gt; m;
    string s = string(n, &apos;.&apos;);
    for (int i = 0; i &amp;lt; m; i++) {
        int t;
        cin &amp;gt;&amp;gt; t;
        t--;
        s[t] = &apos;x&apos;;
    }

    vector &amp;lt;i64&amp;gt; a(n, 0);
    for (int i = 0; i &amp;lt; n; i++) {
        for (int j = 0; j &amp;lt; n; j++) {
            if (i == j) continue;
            if (abs(i - j) &amp;lt;= k) {
                a[i] |= (1LL &amp;lt;&amp;lt; j);
            }
        }
    }

    vector &amp;lt;i64&amp;gt; dp(1LL &amp;lt;&amp;lt; n, -1);
    auto dfs = [&amp;amp;] (auto self, i64 mask, int cnt) -&amp;gt; i64 {
        if (dp[mask] != -1) return dp[mask];
        if (cnt &amp;amp; 1) {
            dp[mask] = 1e11;
        }else {
            dp[mask] = -1e11;
        }

        bool ok = false;
        for (int i = 0; i &amp;lt; n; i++) {
            if (s[i] == &apos;x&apos;) continue;
            if ((mask &amp;gt;&amp;gt; i) &amp;amp; 1) continue;
            if ((mask &amp;amp; a[i]) != 0) continue;
            ok = true;
            i64 nxt = mask | (1LL &amp;lt;&amp;lt; i);
            i64 val = self(self, nxt, cnt + 1);
            if (cnt &amp;amp; 1) {
                dp[mask] = min(dp[mask], val);
            }else {
                dp[mask] = max(dp[mask], val);
            }
        }

        if (!ok) {
            dp[mask] = cnt;
        }

        return dp[mask];
    };
    dfs(dfs, 0LL, 0LL);

    i64 mask = 0LL;
    int cnt = 0;
    
    while (1) {
        int t = -1;
        for (int i = 0; i &amp;lt; n; i++) {
            if (s[i] == &apos;x&apos;) continue;
            if ((mask &amp;gt;&amp;gt; i) &amp;amp; 1) continue;
            if ((mask &amp;amp; a[i]) != 0) continue;

            i64 nxt = mask | (1LL &amp;lt;&amp;lt; i);
            if (dp[nxt] == dp[mask]) {
                t = i;
                break;
            }
        }
        if (t == -1) break;
        if (cnt &amp;amp; 1) {
            s[t] = &apos;b&apos;;
        }else {
            s[t] = &apos;a&apos;;
        }
        mask |= (1LL &amp;lt;&amp;lt; t);
        cnt++;
    }

    cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; &apos;\n&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;C&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定大小为$n \times m$（$1 \leq n, m \leq 1e5$ 且 $n \times m \leq 2e5$）的矩阵，每个格子上都有一个权值$a_{ij}$ $(a_{ij} &amp;lt; 2^{30})$。从左上角$(1, 1)$走到右下角$(n, m)$，设路径上的地点值以此为$a_1, a_2, ... , a_k$，定义消耗的体力为$OR = a_1 \mid a_2 \mid ... \mid a_k$, 定义剩下的物资为$AND = a_1 &amp;amp; a_2 &amp;amp; ... &amp;amp; a_k$。要求在消耗的体力最小的情况下，最大化剩下的物资。输出最小体力消耗和最大物资剩余。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;先满足体力最小的条件，可以从高到低按位枚举确定答案，处理第$i$位时，尝试要求第$i$位全部为$0$。对整张图进行bfs，找出一条路径，其所有的点满足高位贪心结果且第$i$位都为$0$的路径。若不存在，该位只能为$1$。
再满足最大物资剩余的条件，同样从高到低按位枚举，处理第$i$位时，尝试要求第$i$位全部为$1$。在满足体力最小的基础上，找出一条路径，其所有的点满足高位贪心结果且第$i$位都为$1$的路径。若不存在，该位只能为$0$。
时间复杂度：$O(58 \times n \times m)$。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

void solve ()
{
    int n, m;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
    vector &amp;lt;vector &amp;lt;i64&amp;gt; &amp;gt; v(n + 1, vector &amp;lt;i64&amp;gt; (m + 1));
    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            cin &amp;gt;&amp;gt; v[i][j];
        }
    }

    i64 ans1 = 0;
    int t = 0;
    for (int i = 29; i &amp;gt;= 0; i--) {
        if (((v[1][1] &amp;gt;&amp;gt; i) &amp;amp; 1) || ((v[1][1] &amp;amp; t) != 0)) {
            ans1 += (1LL &amp;lt;&amp;lt; i);
            continue;
        }

        vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; vis(n + 1, vector &amp;lt;int&amp;gt; (m + 1, 0));
        queue &amp;lt;array &amp;lt;int, 2&amp;gt; &amp;gt; q;
        q.push({1, 1});
        vis[1][1] = true;
        bool ok = false;
        while (!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            if (x == n &amp;amp;&amp;amp; y == m) {
                ok = true;
                break;
            }
            for (int j = 0; j &amp;lt; 4; j++) {
                int xx = x + dx[j];
                int yy = y + dy[j];
                if (xx &amp;lt; 1 || xx &amp;gt; n || yy &amp;lt; 1 || yy &amp;gt; m) continue;
                if (vis[xx][yy]) continue;
                vis[xx][yy] = true;
                if (((v[xx][yy] &amp;gt;&amp;gt; i) &amp;amp; 1) || (v[xx][yy] &amp;amp; t) != 0) continue;
                q.push({xx, yy});
            }
        }
        if (!ok) {
            ans1 |= (1LL &amp;lt;&amp;lt; i);
        }else {
            t |= (1LL &amp;lt;&amp;lt; i);
        }
    }

    i64 ans2 = 0;
    i64 x = 0;

    for (int i = 29; i &amp;gt;= 0; i--) {
        if (((ans1 &amp;gt;&amp;gt; i) &amp;amp; 1) == 0) continue;
        i64 a = x | (1LL &amp;lt;&amp;lt; i);
        if ((v[1][1] &amp;amp; t) != 0 || (v[1][1] &amp;amp; a) != a) continue;

        vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; vis(n + 1, vector &amp;lt;int&amp;gt; (m + 1, 0));
        queue &amp;lt;array &amp;lt;int, 2&amp;gt; &amp;gt; q;
        q.push({1, 1});
        vis[1][1] = true;
        bool ok = false;
        while (!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            if (x == n &amp;amp;&amp;amp; y == m) {
                ok = true;
                break;
            }
            for (int j = 0; j &amp;lt; 4; j++) {
                int xx = x + dx[j];
                int yy = y + dy[j];
                if (xx &amp;lt; 1 || xx &amp;gt; n || yy &amp;lt; 1 || yy &amp;gt; m) continue;
                if (vis[xx][yy]) continue;
                vis[xx][yy] = true;
                if ((v[xx][yy] &amp;amp; t) != 0 || (v[xx][yy] &amp;amp; a) != a) continue;
                q.push({xx, yy});
            }
        }

        if (ok) {
            ans2 |= (1LL &amp;lt;&amp;lt; i);
            x |= (1LL &amp;lt;&amp;lt; i);
        }
    }

    cout &amp;lt;&amp;lt; ans1 &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; ans2 &amp;lt;&amp;lt; &apos;\n&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>华中师范大学2026菜鸟杯游记及部分题解</title><link>https://blog.everlasting.xin/posts/%E5%8D%8E%E4%B8%AD%E5%B8%88%E8%8C%83%E5%A4%A7%E5%AD%A62026%E8%8F%9C%E9%B8%9F%E6%9D%AF%E6%B8%B8%E8%AE%B0%E9%A2%98%E8%A7%A3/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/%E5%8D%8E%E4%B8%AD%E5%B8%88%E8%8C%83%E5%A4%A7%E5%AD%A62026%E8%8F%9C%E9%B8%9F%E6%9D%AF%E6%B8%B8%E8%AE%B0%E9%A2%98%E8%A7%A3/</guid><description>记录我参加华中师范大学 2026 菜鸟杯的经历，以及部分题目的题解和代码。</description><pubDate>Mon, 23 Mar 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;华中师范大学2026菜鸟杯游记及部分题解&lt;/h1&gt;
&lt;h2&gt;游记&lt;/h2&gt;
&lt;p&gt;下半学期参加的第一场线下赛，打得有点不尽人意。开头被A卡死，一直没发现代码的bug，卡了半个小时，很难受。J题花的时间略有一些长，不过还好过得也算足够快。而后面的H题一直没注意到1e9可拆分的性质，一直不知道怎么写。幸好盯了一会后总算发现，打暴力就行了。而对于后面的偏难的题目有些手足无措的感觉，E题的思路很晚才出，导致F题出了部分思路但后面已经没有时间了。以后得加强难题的训练了。&lt;/p&gt;
&lt;p&gt;午饭挺丰盛的，好评。华师不大，但是风景挺好，已经羡慕了TAT。&lt;/p&gt;
&lt;h2&gt;题解&lt;/h2&gt;
&lt;h3&gt;D&lt;/h3&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    cout &amp;lt;&amp;lt; &quot;CCNU,Ciallo~(&amp;lt;`w&amp;lt; )n*!&quot;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;A&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定字符串A，B，S，将S中与A匹配的部分替换成B。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;简单模拟即可(B题真是。。)&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    int a, b, s;
    cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b &amp;gt;&amp;gt; s;
    string aa, bb, ss;
    cin &amp;gt;&amp;gt; aa &amp;gt;&amp;gt; bb &amp;gt;&amp;gt; ss;
    for (int i = 0; i &amp;lt;= ss.size() - a; i++) { 
        string t = ss.substr(i, a);
        if (t == aa) {
            ss.replace(ss.begin() + i, ss.begin() + i + a, bb);
            i += b - 1;
        }
    } 
    cout &amp;lt;&amp;lt; ss &amp;lt;&amp;lt; &apos;\n&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;I&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定$n$款游戏，要求在一定要送出特定一款游戏的情况下购买最多款游戏。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;简单模拟即可。&lt;s&gt;（赛时以为能购买多个同款游戏而卡了半天）&lt;/s&gt;&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    double m, n;
    cin &amp;gt;&amp;gt; m &amp;gt;&amp;gt; n;
    vector &amp;lt;array &amp;lt;double, 2&amp;gt; &amp;gt; v(n + 1);
    string t = &quot;FemboyLovestory&quot;;
    bool ok = false;
    double x = -1.0;
    for (int i = 1; i &amp;lt;= n; i++) {
        string s;
        cin &amp;gt;&amp;gt; s;
        if (s == t) {
            ok = true;
        }
        i64 a, c;
        cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; c;
        v[i][0] = 1.0 * a * c / 100;
        if (s == t) {
            v[i][1] = 1;
            x = v[i][0];
        }else {
            v[i][1] = 0;
        }
    }

    sort(v.begin() + 1, v.end());

    if (!ok) {
        cout &amp;lt;&amp;lt; 0 &amp;lt;&amp;lt; &apos;\n&apos;;
        return;
    }

    m -= x;
    if (m &amp;lt; 0) {
        cout &amp;lt;&amp;lt; 0 &amp;lt;&amp;lt; &apos;\n&apos;;
        return;
    }
    int ans = 1;
    for (int i = 1; i &amp;lt;= n; i++) {
        if (v[i][1] == 1) continue;
        m -= v[i][0];
        if (m &amp;gt;= 0) ans++;
        else break;
    }

    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;J&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;小A把$N$颗糖以最优策略摆成一长条后，与小B一起从左端开始吃糖。小B先吃。每次吃糖最多吃$3$颗，最少吃$1$颗。$N$颗糖中有一颗特殊的糖，两人都不希望吃到这一颗糖。小B可以随时将特殊的糖移动到右端末尾，但只能移动一次。若小A吃到特殊的糖，输出&quot;Yes&quot;，否则输出&quot;No&quot;。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;简单博弈题。首先因为小B不知道特殊糖的位置，因此无论如何都应该将特殊的糖转移到糖的末端。枚举出糖的数量为$1, 5$时为NO，$2, 3, 4$为YES后，考虑状态转移。在吃糖数量最多吃三颗，最少吃一颗的情况下，$6, 7, 8$颗糖时小B都能将糖的数量转移到$5$的先手必输态，$9$颗糖时无法转移到$5$颗糖的先手必输态。由此可观察出当 $n \bmod 4 == 1$ 时小B必输，其余情况小B必赢。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    i64 n;
    cin &amp;gt;&amp;gt; n;
    if (n % 4 == 1) {
        cout &amp;lt;&amp;lt; &quot;No\n&quot;;
    }else {
        cout &amp;lt;&amp;lt; &quot;Yes\n&quot;;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;C&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;构造一个含有$n$个$0$和$m$个$1$的字符串S，满足字符串中任意一个子段满足子段中$0$的个数和$1$的个数的绝对值差值小于等于$k$且至少存在一个子段差值等于$k$。保证存在一个合法的解。&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;简单构造题。题目保证了存在合法的解，我们便可以先满足至少存在一个子段差值等于$k$的条件。先让个数多的输出$k$个后再01或10地交替，这样保证了最优的构造。最后若有剩下的，因为题目保证合法，直接输出即可。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;void solve ()
{
    int n, m, k;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m &amp;gt;&amp;gt; k;
    if (n &amp;gt; m) {
        for (int i = 0; i &amp;lt; k; i++) {
            cout &amp;lt;&amp;lt; &apos;0&apos;;
        }
        int t0 = n - k;
        for (int i = 0; i &amp;lt; t0; i++) {
            cout &amp;lt;&amp;lt; &quot;10&quot;;
        }
        int l = m - t0;
        for (int i = 0; i &amp;lt; l; i++) {
            cout &amp;lt;&amp;lt; &apos;1&apos;;
        }
    }else {
        for (int i = 0; i &amp;lt; k; i++) {
            cout &amp;lt;&amp;lt; &apos;1&apos;;
        }
        int t0 = m - k;
        for (int i = 0; i &amp;lt; t0; i++) {
            cout &amp;lt;&amp;lt; &quot;01&quot;;
        }
        int l = n - t0;
        for (int i = 0; i &amp;lt; l; i++) {
            cout &amp;lt;&amp;lt; &apos;0&apos;;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;H&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定$T$组两个整数$n$, $m$，满足$n &amp;lt; m$,计算$n \times (n + 1) \times (n + 2) \times ··· \times m$对$1e9$取模后的结果。
$(1 \leq n \leq m \leq 1e9)$
$(1 \leq T \leq 1e5)$&lt;/p&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;$1e9$由$9$个$2$和$9$个$5$相乘组成，由于只有$1e5$组数据，直接暴力计算$1e3$个数绝对是够的（事实上只用$40$个数据就够了）。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;const i64 mod = 1e9;

void solve ()
{
    i64 n, m;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
    i64 res = m % mod;
    for (int i = m - 1; i &amp;gt;= max(m - 1000, n); i--) {
        res = (res * i) % mod;
    }
    cout &amp;lt;&amp;lt; res &amp;lt;&amp;lt; &apos;\n&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;E&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;Windows和Soubai比赛谁能活到最后，其生命值分别为$x$，$y$，实力分别为$A$，$B$，Boss的实力为$C$。
比赛每轮会恰好发生三种事件之一，直至有人生命值小于等于$0$：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Windows有$A / C$的概率命中Soubai，对Soubai造成等于其自身生命值的伤害。&lt;/li&gt;
&lt;li&gt;Soubai有$B / C$的概率命中Windows，对Windows造成等于其自身生命值的伤害。&lt;/li&gt;
&lt;li&gt;双方有$1 - A / C - B / C$的概率均未命中。
求出Windows赢得比赛的概率。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;首先可以简化模型，因为平局对胜负无影响，所以我们可以忽略平局。设$p_0$,$p_1$分别为Windows打到Soubai的概率和Soubai打到Windows的概率。其中$p_0 = A / (A + B)$，$p_1 = B / (A + B)$。
我们可以根据生命值的大小分成三种情况，分别为$x &amp;gt; y$, $x &amp;lt; y$和$x = y$。我们需要维护至当前状态所需要的概率$res$。&lt;/p&gt;
&lt;p&gt;当$x &amp;gt; y$时，要想使回合进行下去，只能由Soubai攻击Windows，同时每次攻击之后，Windows都能够直接击杀Soubai。因此在当前状态下，设Soubai能够攻击Windows的次数为$cnt$，Windows能赢得的概率为：$P = res * (p_0 + p_0 * p_1 + ··· + p_0 * p_1^{cnt})$,即$P = \frac{res \cdot p_0 \cdot p_1 \left(p_1^{\mathrm{cnt}} - 1\right)}{p_1 - 1}$。&lt;/p&gt;
&lt;p&gt;当$x &amp;lt; y$时，要想使回合进行下去，只能由Windows攻击Soubai。但是这个时候不会出现Windows赢得比赛的情况，因此在当前状态下，只需要简单维护$res$即可。&lt;/p&gt;
&lt;p&gt;当$x = y$时，只能由Windows攻击Soubai后得到答案。&lt;/p&gt;
&lt;p&gt;直到$x$或$y$小于等于$0$时，结束比赛，输出答案即可。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;const i64 mod = 998244353;

i64 qpow (i64 a, i64 b) {
    i64 res = 1;
    while (b) {
        if (b &amp;amp; 1) res = res * a % mod;
        a = a * a % mod;
        b &amp;gt;&amp;gt;= 1;
    }
    return res;
}

void solve ()
{
    i64 x, y, a, b, c;
    cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; y &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b &amp;gt;&amp;gt; c;
    
    i64 ans = 0;
    i64 res = 1;
    i64 p0 = a * qpow(a + b, mod - 2) % mod;
    i64 p1 = b * qpow(a + b, mod - 2) % mod;

    auto cal1 = [&amp;amp;] (i64 &amp;amp;x, i64 &amp;amp;y) {
        i64 cnt = x / y - (x % y == 0 ? 1 : 0);
        i64 sum = res * (1 + (mod - qpow(p1, cnt)) % mod) % mod;
        sum = sum * qpow((1 + mod - p1) % mod, mod - 2) % mod;
        ans = (ans + (sum * p0) % mod) % mod;
        res = res * qpow(p1, cnt) % mod;
        x -= cnt * y;
    };

    auto cal2 = [&amp;amp;] (i64 &amp;amp;x, i64 &amp;amp;y) {
        i64 cnt = y / x - (y % x == 0 ? 1 : 0);
        res = res * qpow(p0, cnt) % mod;
        y -= cnt * x;
    };

    while (x &amp;gt; 0 &amp;amp;&amp;amp; y &amp;gt;  0) {
        if (x &amp;gt; y) {
            cal1(x, y);
        }else if (x &amp;lt; y) {
            cal2(x, y);
        }else {
            ans = (ans + (res * p0 % mod)) % mod;
            break;
        }
    } 

    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;

}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;F&lt;/h3&gt;
&lt;h4&gt;题意&lt;/h4&gt;
&lt;p&gt;给定一个长度为$n$的数组$a$，要求支持一共$q$次的以下两种操作:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;输入$1 x v$，将数组下标为$x$的元素改成$v$。&lt;/li&gt;
&lt;li&gt;输入$2 p$，查询可重集合$ {a_1 \bmod p, a_2 \bmod p, ···, a_n \mod p}$的中位数。
$(1 \leq n \leq 1e5, 1 \leq q \leq 1e5)$
$(1 \leq a_i \leq 2e5)$
$(1 \leq x \leq n, 0 \leq v \leq 2e5, 1 \leq p \leq 2e5)$&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;思路&lt;/h4&gt;
&lt;p&gt;很容易想到使用树状数组维护每一个值出现的个数并进行修改和查询。对于查询中位数而言，则是经典的根号分治的思想。对于小于$\sqrt {2e5}$的数，只需维护每一个小于$\sqrt {2e5}$的余数出现的次数即可，而对于大于$\sqrt {2e5}$的数，只需在每一个区间进行二分即可。这样即可解决中位数的问题了。&lt;/p&gt;
&lt;h4&gt;代码&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;const int m = 450;
const int mx = 2e5 + 5;

class BIT {
    public:
        int n;
        vector &amp;lt;i64&amp;gt; bit;

        BIT (int n = 0) {init(n);}
    
        void init (int m) {
            n = m;
            bit.assign(n + 1, 0);
        }

        static i64 lowbit (i64 x) { return x &amp;amp; -x; }

        i64 sum (int idx) const {
            i64 res = 0;
            for (; idx &amp;gt; 0; idx -= lowbit(idx)) res += bit[idx];
            return res; 
        }

        void point_add (int idx, i64 diff) {
            for (; idx &amp;lt;= n; idx += lowbit(idx)) bit[idx] += diff;
        }

        i64 point_query (int idx) const {
            return sum(idx) - sum(idx - 1);
        }

};

void solve ()
{
    int n, q;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; q;
    vector &amp;lt;int&amp;gt; v(n + 1);
    for (int i = 1; i &amp;lt;= n; i++) {
    	cin &amp;gt;&amp;gt; v[i];
    }

    BIT bit(mx + 2);
    for (int i = 1; i &amp;lt;= n; i++) {
    	bit.point_add(v[i] + 1, 1);
    }

    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; a(m + 1);
    for (int i = 1; i &amp;lt;= m; i++) {
    	a[i].assign(i, 0);
    }
    for (int i = 1; i &amp;lt;= n; i++) {
    	for (int j = 1; j &amp;lt;= m; j++) {
    		a[j][v[i] % j]++;
    	}
    }

    while (q--) {
    	int op;
    	cin &amp;gt;&amp;gt; op;
    	if (op == 1) {
    		int x, b;
    		cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; b;
    		if (v[x] == b) continue;
    		bit.point_add(v[x] + 1, -1);
    		bit.point_add(b + 1, 1);
    		for (int i = 1; i &amp;lt;= m; i++) {
    			a[i][v[x] % i]--;
    			a[i][b % i]++;
    		}
    		v[x] = b;
    	}else {
    		int x;
    		cin &amp;gt;&amp;gt; x;
    		if (x &amp;lt;= m) {
    			int sum = 0;
    			int ans = 0;
    			for (int i = 0; i &amp;lt; x; i++) {
    				sum += a[x][i];
    				if (sum &amp;gt;= (n + 1) / 2) {
    					ans = i;
    					break;
    				}
    			}
    			cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
    		}else {
    			int l = 0, r = x - 1;
    			int ans = x - 1;

    			auto check = [&amp;amp;] (int md) -&amp;gt; bool {
    				int res = 0;
    				for (int i = 0; i &amp;lt;= mx; i += x) {
    					res += bit.sum(min(i + md, mx) + 1) - bit.sum(i);
    				}
    				return res &amp;gt;= (n + 1) / 2;
    			};

    			while (l &amp;lt;= r) {
    				int mid = l + (r - l) / 2;
    				if (check(mid)) {
    					r = mid - 1;
    				}else {
    					l = mid + 1;
    				}
    			}
    			cout &amp;lt;&amp;lt; l &amp;lt;&amp;lt; &apos;\n&apos;;
    		}
    	}
    }
} 
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>天梯赛普及赛编程题题解</title><link>https://blog.everlasting.xin/posts/%E5%A4%A9%E6%A2%AF%E8%B5%9B%E6%99%AE%E5%8F%8A%E8%B5%9B%E9%A2%98%E8%A7%A3/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/%E5%A4%A9%E6%A2%AF%E8%B5%9B%E6%99%AE%E5%8F%8A%E8%B5%9B%E9%A2%98%E8%A7%A3/</guid><description>整理天梯赛普及赛编程题的题解与代码实现。</description><pubDate>Sat, 14 Mar 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;天梯赛普及赛编程题题解&lt;/h1&gt;
&lt;h1&gt;天梯赛普及赛编程题题解&lt;/h1&gt;
&lt;h2&gt;1&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    cout &amp;lt;&amp;lt; &quot;If people never did silly things, nothing intelligent would ever get done.&quot;;
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;2&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int x, n, y;
    cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; n &amp;gt;&amp;gt; y;
    cout &amp;lt;&amp;lt; x * n + y &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;3&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int a, b, c;
    cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b &amp;gt;&amp;gt; c;
    cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &apos;\n&apos;;
    if (a &amp;lt; b) {
        cout &amp;lt;&amp;lt; &quot;Bu Kan&quot;;
    }else if (a &amp;gt;= b &amp;amp;&amp;amp; a &amp;lt; c) {
        cout &amp;lt;&amp;lt; &quot;Zhe Gua Bao Shu Ma&quot;;
    }else {
        cout &amp;lt;&amp;lt; &quot;Chi Gua&quot;;
    }
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;4&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;
    int ans = 0;
    for (int i = 1; i &amp;lt;= n; i++) {
        int t;
        cin &amp;gt;&amp;gt; t;
        if (!(i &amp;amp; 1)) {
            ans += t;
        }
    }
    cout &amp;lt;&amp;lt; ans;
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;5&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int a, b;
    cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b;
    int res = a + b;
    int t;
    int ans = 1;
    while (cin &amp;gt;&amp;gt; t) {
        if (t == res) {
            cout &amp;lt;&amp;lt; res &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; &quot;Accepted &quot;;
            int l = ans % 60;
            int minute = ((ans - l) / 60) % 60;
            int hour = (ans - l - minute * 60) / 3600;
            if (hour &amp;lt;= 9) cout &amp;lt;&amp;lt; &quot;0&quot; &amp;lt;&amp;lt; hour;
            else cout &amp;lt;&amp;lt; hour;
            cout &amp;lt;&amp;lt; &quot;:&quot;;
            if (minute &amp;lt;= 9) cout &amp;lt;&amp;lt; &quot;0&quot; &amp;lt;&amp;lt; minute;
            else cout &amp;lt;&amp;lt; minute;
            cout &amp;lt;&amp;lt; &quot;:&quot;;
            if (l &amp;lt;= 9) cout &amp;lt;&amp;lt; &quot;0&quot; &amp;lt;&amp;lt; l;
            else cout &amp;lt;&amp;lt; l;
            return;
        }
        ans += 2;
        if (ans &amp;gt;= 10800) {
            ans = 10799;
            break;
        }
    }

    cout &amp;lt;&amp;lt; t &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; &quot;Wrong Answer &quot; &amp;lt;&amp;lt; &quot;02:59:59&quot;;
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;6&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;
    for (int i = 1; i &amp;lt;= n; i++) {
        int t;
        int ans = 0;
        bool ok = false;
        map &amp;lt;int, int&amp;gt; mp;
        while (cin &amp;gt;&amp;gt; t) {
            if (t == -1) break;
            if (!ok &amp;amp;&amp;amp; mp[t]) {
                ans = t;
                ok = true;
            }
            mp[t] = true;
        }
        if (ok) {
            cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;NONE\n&quot;;
        }
    }
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;7&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;

    auto cal1 = [&amp;amp;] (i64 x) -&amp;gt; bool {
        i64 res = 0;
        while (res * res * 2 &amp;lt;= x) {
            if (res * res * 2 == x) return true;
            res++;
        }
        if (res * res * 2 == x) return true;
        else return false;
    };

    auto cal2 = [&amp;amp;] (i64 x) -&amp;gt; bool {
        i64 res = 0;
        while (res * res * res * 3 &amp;lt;= x) {
            if (res * res * res * 3 == x) return true;
            res++;
        }
        if (res * res * res * 3 == x) return true;
        else return false;
    };
 
    for (int i = 1; i &amp;lt;= n; i++) {
        i64 t;
        cin &amp;gt;&amp;gt; t;
        bool ok1 = cal1(t);
        bool ok2 = cal2(t);
        if (ok1 &amp;amp;&amp;amp; ok2) {
            cout &amp;lt;&amp;lt; t &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; &quot;is a triple flower&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (ok1 &amp;amp;&amp;amp; !ok2) {
            cout &amp;lt;&amp;lt; t &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; &quot;is a double flower&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; t &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; &quot;is&quot; &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; t &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;8&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int n;
    cin &amp;gt;&amp;gt; n;
    for (int i = 1; i &amp;lt;= n; i++) {
        vector &amp;lt;i64&amp;gt; v;
        v.reserve(10001);
        i64 t;
        while (cin &amp;gt;&amp;gt; t) {
            if (t == -1) break;
            v.push_back(t);
        } 
        int m = v.size();
        bool ok = false;
        i64 ans1, ans2, ans3;
        unordered_map &amp;lt;i64, vector &amp;lt;int&amp;gt; &amp;gt; mp;
        for (int i = 0; i &amp;lt; m; i++) {
            if (i == m - 1 || i == m - 2) continue;
            mp[v[i]].push_back(i);
        }

        vector &amp;lt;array &amp;lt;i64, 4&amp;gt; &amp;gt; ans;
        unordered_map &amp;lt;int, int&amp;gt; mpp;
        mpp[v[m - 1]] = true;
        mpp[v[m - 2]] = true;
        for (int i = 0; i &amp;lt; m - 2; i++) {
            if (mpp[v[i]]) continue;
            i64 a = v[i + 1], b = v[i + 2];
            bool found = true;
            int cnt = 0;
            int pos = 0;
            for (auto x : mp[v[i]]) {
                i64 c = v[x + 1], d = v[x + 2];
                if (c != a || d != b) {
                    found = false;
                    break;
                }
                cnt++;
                if (cnt == 2) {
                    pos = x;
                }
                // cout &amp;lt;&amp;lt; v[i] &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; pos &amp;lt;&amp;lt; &apos;\n&apos;;
            }
            if (found &amp;amp;&amp;amp; cnt &amp;gt;= 2) {
                ok = true;
                ans.push_back({pos, v[i], a, b});
            }
            mpp[v[i]] = true;
        }

        if (ans.size()) sort(ans.begin(), ans.end());
        if (ans.size()) {
            cout &amp;lt;&amp;lt; ans[0][1] &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; ans[0][2] &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; ans[0][3] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;NONE\n&quot;;
        }
    }
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;9&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using i64 = long long;

void solve ()
{
    int n, m;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; e(m + 5);
    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; v(n + 5);
    v.reserve(201 * 1001);
    for (int i = 1; i &amp;lt;= n; i++) {
        int t;
        cin &amp;gt;&amp;gt; t;
        v[i].reserve(1001);
        for (int j = 1; j &amp;lt;= t; j++) {
            int b;
            cin &amp;gt;&amp;gt; b;
            v[i].push_back(b);
            e[b].push_back(i);
        }
        sort(v[i].begin(), v[i].end());
        v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
    }

    vector &amp;lt;vector &amp;lt;int&amp;gt; &amp;gt; a(n + 5);
    int cnt = 1;
    vector &amp;lt;int&amp;gt; vis(m + 5);
    vector &amp;lt;int&amp;gt; viss(n + 5);

    auto dfs = [&amp;amp;] (auto self, int u) -&amp;gt; void {
        for (auto x : e[u]) {
            if (viss[x]) continue;
            viss[x] = true;
            for (auto y : v[x]) {
                if (vis[y]) continue;
                vis[y] = true;
                a[cnt].push_back(y);
                self(self, y);
            }
        }
    };

    for (int i = 1; i &amp;lt;= m; i++) {
        if (vis[i]) continue;
        vis[i] = true;
        a[cnt].push_back(i);
        dfs(dfs, i);
        cnt++;
    }

    for (int i = 1; i &amp;lt; cnt; i++) {
        sort(a[i].begin(), a[i].end());
        if (i == cnt - 1) cout &amp;lt;&amp;lt; a[i][0];
        else cout &amp;lt;&amp;lt; a[i][0] &amp;lt;&amp;lt; &apos; &apos;;
    }
}

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>Codeforces Round 1072 (Div.3) E题题解</title><link>https://blog.everlasting.xin/posts/codeforces_round_1072_e/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/codeforces_round_1072_e/</guid><description>记录 Codeforces Round 1072 (Div.3) E 题的思路分析与代码实现。</description><pubDate>Tue, 13 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;Codeforces Round 1072 (Div.3) E题题解&lt;/h1&gt;
&lt;h2&gt;题意：&lt;/h2&gt;
&lt;p&gt;定义精致数组-$k$为任意相邻两数之差至少为$k$的数组。&lt;/p&gt;
&lt;p&gt;给定长度为$n$的排列$p$，对于每一个从$1$到$n - 1$的$k$，找出精致数组-$k$的数量。&lt;/p&gt;
&lt;p&gt;&amp;lt;!-- more --&amp;gt;&lt;/p&gt;
&lt;h2&gt;思路：&lt;/h2&gt;
&lt;p&gt;题目要求: 寻找相邻差值至少为$k$的数组个数。&lt;/p&gt;
&lt;p&gt;这可以转化为：寻找差分数组中某一子段的最小值至少为$k$的数组个数。&lt;/p&gt;
&lt;p&gt;这仍然很麻烦。于是我们可以先统计出最小值为$k,k\in [1, n - 1]$的子段数，最后再做前缀和即可转换为最小值至少为$k$的数组个数。&lt;/p&gt;
&lt;p&gt;关于统计最小值为$k$的子段数，我们可以对差分数组中的每一个数进行单独计算：&lt;/p&gt;
&lt;p&gt;对于第$i$个差值，我们可以利用两次单调栈统计出第$i$个差值左侧最近的满足$d[l]&amp;lt;=d[i]$的$l$和右侧最近的满足$d[r]&amp;lt;d[i]$的$r$，这样即可以求出对于当前的$d[i]$，以$d[i]$为最小值的数组个数：$(i - l + 1 - 1) \times (r - i + 1 - 1)$，即：$(i - l) \times (r - i)$。&lt;/p&gt;
&lt;p&gt;这样即可不重不漏地统计出所有最小值为$k$的子段数，最后再从$1$到$n$做前缀和即可求出最小值至少为$k$的数组个数。&lt;/p&gt;
&lt;h2&gt;代码：&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ld = long double;
#define int long long
#define fi first
#define se second

void solve ()
{
    int n; cin &amp;gt;&amp;gt; n;
    vector &amp;lt;int&amp;gt; v(n + 1), d(n + 3);
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; v[i];
        d[i] = abs(v[i] - v[i - 1]);
    }

    vector &amp;lt;int&amp;gt; al(n + 3, 1), br(n + 3, n + 1);
    vector &amp;lt;int&amp;gt; stk;

    for (int i = 2; i &amp;lt;= n; i++) {
        while (stk.size() &amp;amp;&amp;amp; d[stk.back()] &amp;gt; d[i]) {
            stk.pop_back();
        }
        if (stk.size()) al[i] = stk.back();
        stk.push_back(i);
    }

    stk.clear();
    for (int i = n; i &amp;gt;= 2; i--) {
        while (stk.size() &amp;amp;&amp;amp; d[stk.back()] &amp;gt;= d[i]) {
            stk.pop_back();
        }
        if (stk.size()) br[i] = stk.back();
        stk.push_back(i);
    }

    vector &amp;lt;int&amp;gt; ans(n + 1, 0);
    for (int i = 2; i &amp;lt;= n; i++) {
        ans[d[i]] += (br[i] - i) * (i - al[i]);
    }

    for (int i = n - 2; i &amp;gt;= 1; i--) {
        ans[i] += ans[i + 1];
    }

    for (int i = 1; i &amp;lt; n; i++) {
        cout &amp;lt;&amp;lt; ans[i] &amp;lt;&amp;lt; &quot; \n&quot;[i == n - 1];
    }
}   
    
signed main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>C语言作业答案(上)</title><link>https://blog.everlasting.xin/posts/c_homework_part1/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/c_homework_part1/</guid><description>整理 C 语言作业上半部分的参考答案，方便复习与查阅。</description><pubDate>Wed, 07 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;C语言作业答案(上)&lt;/h1&gt;
&lt;p&gt;临近期末，打开oj，一笔没动，怎么办！&lt;/p&gt;
&lt;p&gt;不用担心。这里有人经历过。为了不让更多的人经历如此磨难，现有答案供君参考。&lt;/p&gt;
&lt;p&gt;若答案顺序与作业顺序不同，可联系笔者！&lt;/p&gt;
&lt;p&gt;&amp;lt;!-- more --&amp;gt;&lt;/p&gt;
&lt;p&gt;下给出笔者邮箱：2279839810@qq.com&lt;/p&gt;
&lt;h2&gt;第一章&lt;/h2&gt;
&lt;h3&gt;求圆的面积和周长&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double r;
	double s, c;
	const double K=3.140000;
	
	scanf(&quot;%lf&quot;, &amp;amp;r);
	
	s=K*r*r;
	c=2*K*r;
	
	printf(&quot;%lf\n%lf&quot;, s, c);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求2个整数的和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b;
	
	scanf(&quot;%d %d&quot;, &amp;amp;a, &amp;amp;b);
	
	int c=a+b;
	
	printf(&quot;%d&quot;,c);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;输出2行信息&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	printf(&quot;Programing is fun.\n&quot;);
	printf(&quot;Programing in language C is even more fun!&quot;);
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Hello World!&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	printf(&quot;Hello World!&quot;);
	
	return 0;
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计函数求2个整数的最大值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
int max (int x, int y) {
    if (x &amp;gt;= y) {
        return x;
    } else {
        return y;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求2个整数的最大值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b, max;
	
	scanf(&quot;%d %d&quot;, &amp;amp;a, &amp;amp;b);
	
	if (a&amp;gt;b) max=a;
	else max=b;
	
	printf(&quot;max=%d&quot;,max);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;This is a C program&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	printf(&quot;This is a C program&quot;);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第二章&lt;/h2&gt;
&lt;h3&gt;猫是液体&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int a, b, c;
	scanf(&quot;%d %d %d&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c);
	
	int v = a * b * c;
	
	printf(&quot;%d&quot;, v);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;中英长度单位换算&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int cm, foot, inch;
	
	scanf(&quot;%d&quot;, &amp;amp;cm);
	
    int t=cm/30.48;
	
	double n=cm/30.48;
	
	foot=t;
	
	inch=(n-t)*12;
	
	printf(&quot;%d %d&quot;, foot, inch)	;
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;打妖怪&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b, c;
	
	scanf(&quot;%d %d&quot;, &amp;amp;a, &amp;amp;b);
	
	int rem=a%b;
	int t=a/b;
	
	if (rem==0)
	   printf(&quot;%d&quot;, t);
	   
	else 
	   printf(&quot;%d&quot;, t+1);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求整数均值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b, c, d;
	
	scanf(&quot;%d %d %d %d&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c, &amp;amp;d);
	
	int sum=a+b+c+d;
	double aver=(a+b+c+d)/4.00;
	
	printf(&quot;Sum = %d\nAverage = %.2f&quot;, sum, aver);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;整数四则运算&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b;
	
	scanf(&quot;%d %d&quot;, &amp;amp;a, &amp;amp;b);
	
	printf(&quot;%d + %d = %d\n&quot;, a, b, a+b); 
	printf(&quot;%d - %d = %d\n&quot;, a, b, a-b);
	printf(&quot;%d * %d = %d\n&quot;, a, b, a*b);
	printf(&quot;%d / %d = %d&quot;, a, b, a/b);
		   
	return 0;	   
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;分糖果&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int x, y, z;
	scanf(&quot;%d %d %d&quot;, &amp;amp;x, &amp;amp;y, &amp;amp;z);
	
	int a = x / 3;
	x = a;
	y += a;
	z += a;
	
	int b = y / 3;
	x += b;
	y = b;
	z += b;
	
	int c = z / 3;
	x += c;
	y += c;
	z = c;
	
	printf(&quot;%d %d %d&quot;, x, y, z);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;自由落体&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int t;
	scanf(&quot;%d&quot;, &amp;amp;t);
	
	int h = 10 * t * t / 2;
	
	if (h &amp;gt; 2000) {
		printf(&quot;2000&quot;);
	}else {
		printf(&quot;%d&quot;, h);
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算终止时间&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

int main () 
{
    char str[4];
    double num;
    int a;
    
    scanf(&quot;%s %d&quot;, &amp;amp;str, &amp;amp;a);
    
    num = atof(str);
    
    int NUM = num;
    
    int min = NUM % 100;
    int hour = NUM / 100;
    
    int res = a + min;
    
    if (res &amp;gt;= 60) {
    	int temp = res / 60;
    	hour += temp;
    	res -= temp * 60;
	}else if (res &amp;lt; 0) {
		res = -res;
		int temp = res / 60;
		hour -= temp + 1;
		res -= temp * 60;
		res = 60 - res;
	}
	
	if (res &amp;gt;= 60) {
    	int temp = res / 60;
    	hour += temp;
    	res -= temp * 60;
    }

	printf(&quot;%d%02d&quot;, hour, res);

    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;输出四位整数的各位数字&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int num;
	
	scanf(&quot;%d&quot;, &amp;amp;num);
	
	int a=num/1000, 
	    b=num/100-a*10, 
	    c=num/10-a*100-b*10,
	    d=num-a*1000-b*100-c*10;
	
	printf(&quot;%d=%d+%d*10+%d*100+%d*1000&quot;, num, d, c, b, a);
	
	return 0;
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;两小时学完C语言&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n, k ,m;
	
	scanf(&quot;%d %d %d&quot;, &amp;amp;n, &amp;amp;k, &amp;amp;m);
	
	int remain=n-k*m;
	
	printf(&quot;%d&quot;, remain);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算图形面积&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b;
	
	scanf(&quot;%d %d&quot;, &amp;amp;a, &amp;amp;b);
	
	int s=abs(50*a-50*b);
	
	printf(&quot;%d&quot;, s);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;折扣&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int ori, dis;
	
	scanf(&quot;%d %d&quot;, &amp;amp;ori, &amp;amp;dis);
	
	double final=ori*dis/10.00;
	
	printf(&quot;%.2f&quot;, final);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;标准体重和身高的对应关系&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int h=0;
	
	scanf(&quot;%d&quot;, &amp;amp;h);
	
	double m=(h-100)*0.9*2;
	
	printf(&quot;%.1f&quot;, m);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;后天&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int D=0;
	
	scanf(&quot;%d&quot;, &amp;amp;D);
	
	D+=2;
	
	if(D&amp;gt;7) D-=7;
	
	printf(&quot;%d&quot;, D);
	
	return 0;
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第三章&lt;/h2&gt;
&lt;h3&gt;字母对应的ASCII 码&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	char ch;
	
	scanf(&quot;%c&quot;, &amp;amp;ch);
	
	printf(&quot;%d&quot;, ch);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;温度转换&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double f=0;
	
	scanf(&quot;%lf&quot;, &amp;amp;f);
	
	double c=5.0/9.0*(f-32);
	
	printf(&quot;%lf&quot;, c);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算圆的周长&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double r;
	double K=3.14;
	
	scanf(&quot;%lf&quot;, &amp;amp;r);
	
    double c=2*K*r;
    
    printf(&quot;%lf&quot;, c);
    
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求三位整数的逆序数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int num = 0;
	int result = 0;
	int digital = 0;
	
	scanf(&quot;%d&quot;, &amp;amp;num);
	
	while (num &amp;gt; 0){
		digital = num % 10;
		result = result * 10 + digital; 
		num /= 10;
	}
	
	printf(&quot;%03d&quot;, result);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求三角形面积&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

int main()
{
    double a, b, c;
    
    scanf(&quot;%lf %lf %lf&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c);
    
    double p = (a + b + c) / 2;
    
    double s = sqrt(p * (p - a) * (p - b) * (p - c));
    
    printf(&quot;%.2f&quot;, s);
    
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算浮点数相除的余数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double a, b;
	
	scanf(&quot;%lf %lf&quot;, &amp;amp;a, &amp;amp;b);
	
	int k=0;
    double tag=0.0;
    double n=0.0;
    
    do{
    	n=a-k*b;
    	k++;
	}while (n&amp;gt;=0);
	
	double r=n+b;
	
	printf(&quot;%g&quot;, r);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;年增长率&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

int main()
{
	int n;
	
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	double x=pow(2.0, 1.0/n);
	
	double res=(x-1.0)*100;
	
	printf(&quot;%.2f%%&quot;, res);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;快速求和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int tag;
	double s=0.0;
	
	for (tag=1; tag&amp;lt;=n; tag++){
		s+=1.0/(tag*(tag+1.0));
	}
	
	printf(&quot;%.5f&quot;, s);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;混合类型数据格式化输入&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double a, b;
	int c;
	char d;
	
	scanf(&quot;%lf %d %c %lf&quot;, &amp;amp;a, &amp;amp;c, &amp;amp;d, &amp;amp;b);
	
	printf(&quot;%c %d %.2f %.2f&quot;, d, c, a, b);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;定期存款&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double a, b;
	
	scanf(&quot;%lf %lf&quot;, &amp;amp;a, &amp;amp;b);
	
	double res1=a*b/100.0;
	
	double res2=res1+a;
	
	printf(&quot;%11.2f\n%11.2f\n%11.2f&quot;, a, res1, res2);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;日期格式变化&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int m, d, y;
	
	scanf(&quot;%d-%d-%d&quot;, &amp;amp;m, &amp;amp;d, &amp;amp;y);
	
	printf(&quot;%02d-%02d-%02d&quot;, y, m, d);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;水果店收款&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double a, b, c, d;
	
	scanf(&quot;%lf %lf %lf %lf,&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c, &amp;amp;d);
	
	double p=2.5*a+1.7*b+2*c+1.2*d;
	
	printf(&quot;%.2f&quot;, p);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算房间面积&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double a, b;
	
	scanf(&quot;%lf\n%lf&quot;, &amp;amp;a, &amp;amp;b);
	
	double c=a*b;
	
	printf(&quot;the area of the room:%lf&quot;, c);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第四章&lt;/h2&gt;
&lt;h3&gt;三天打鱼两天晒网&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int tag = n % 5;
	
	switch (tag) {
		case 1:
		case 2:
		case 3:
			printf(&quot;Fishing in day %d&quot;, n);
		    break;
		    
		default:
			printf(&quot;Drying in day %d&quot;, n);
	}
	
	return 0;
	
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;闰年&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int yr;
	scanf(&quot;%d&quot;, &amp;amp;yr);
	
	int mask1 = yr%400;
	int lpyr = 0;
	
	int mask2 = yr%4;
	int mask3 = yr%100;
	
	if (mask1 == 0) {
		lpyr = 1;
	}else {
		if (mask2 == 0) {
			if (mask3 != 0 ){
				lpyr = 1;
			}
		}
	}
	
	if (lpyr == 1) {
		printf(&quot;%d is a leap year!&quot;, yr);
	}else {
		printf(&quot;%d isn&apos;t a leap year!&quot;, yr);
	}
	
	return 0;
	
}



&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;三个整数排序&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b, c;
	scanf(&quot;%d %d %d&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c);
	
	int num1, num2, num3;
	
	if (a &amp;gt; b) {
		if (a &amp;gt; c){
			num1 = a;
			if (b &amp;gt; c){
			    num2 = b, num3 = c;
		    }else {
			    num2 = c, num3 = b;
		        }
	        }else {
	        num1 = c, num2 = a, num3 = b;
			} 
		
	}else{
		if (b &amp;gt; c){
			num1 = b;
			if (a &amp;gt; c){
				num2 = a, num3 = c;
			}else {
				num2 = c, num3 = a;
			}
		}else{
			num1 = c, num2 = b, num3 = a;
		}
	}
	
	printf(&quot;a=%d,b=%d,c=%d&quot;, num3, num2, num1);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;判断水仙花数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int num;
	scanf(&quot;%d&quot;, &amp;amp;num);
	
	int a, b, c;
	a = num / 100;
	b = num / 10 - a * 10;
	c = num - a * 100 - b * 10;
	
	int A = 1;
	int B = 1;
	int C = 1;
	
	int cnt = 0;
	
	
	do {
		A *= a;
		B *= b;
		C *= c;
		
		cnt++;
		
	}while (cnt != 3);
	
	int res;
	res = A + B + C;
	
	if (res == num) {
		printf(&quot;YES&quot;);
		
	}else {
		printf(&quot;NO&quot;);
	}
	
	return 0;
	
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算奖金&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	double p;
	scanf(&quot;%lf&quot;, &amp;amp;p);
	
	double bonus;
	
	if (p &amp;lt;= 100000) {
		bonus = p * 0.10;

	}else if (p &amp;gt; 100000 &amp;amp;&amp;amp; p &amp;lt;= 200000) {
		bonus = 10000 + (p - 100000) * 0.075;

	}else if (p &amp;gt; 200000 &amp;amp;&amp;amp; p &amp;lt;= 400000) {
		bonus = 17500 + (p - 200000) * 0.05;

	}else if (p &amp;gt; 400000 &amp;amp;&amp;amp; p &amp;lt;= 600000) {
		bonus = 27500 + (p - 400000) * 0.03;

	}else if (p &amp;gt; 600000 &amp;amp;&amp;amp; p &amp;lt;= 1000000) {
		bonus = 33500 + (p - 600000) * 0.015; 

	}else if (p &amp;gt; 1000000) {
		bonus = 39500 + (p - 1000000) * 0.01; 
	
	}//恶心 
	
	printf(&quot;%.2f&quot;, bonus);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;按公式计算y和z的值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

int main()
{
	double x = 0.0;
	scanf (&quot;%lf&quot;, &amp;amp;x);
	
	double y, z;
	
	if (x &amp;gt;= 1 &amp;amp;&amp;amp; x &amp;lt; 2) {
		y = x * x + 1.0;
		z = 3.0 * x + 5.0;
	}else if (x &amp;gt;= 2 &amp;amp;&amp;amp; x &amp;lt;= 2.5) {
		y = x * x + 1.0;
		z = 2.0 * sin(x) - 1.0;
	}else if (x &amp;gt; 2.5 &amp;amp;&amp;amp; x &amp;lt; 3) {
		y = x * x - 1.0;
		z = 2.0 * sin (x) - 1.0;
	}else if (x &amp;gt;= 3 &amp;amp;&amp;amp; x &amp;lt; 5) {
		y = x * x - 1.0;
		z = sqrt (1.0 + x * x);
	}else if (x &amp;gt;= 5 &amp;amp;&amp;amp; x &amp;lt; 8) {
		y = x * x - 1.0;
		z = x * x - 2 * x + 5;
	}
	
	printf(&quot;%lf\n%lf&quot;, y, z);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;24小时时间记法转12小时时间记法&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int hor, min, sec;
	scanf(&quot;%d %d %d&quot;, &amp;amp;hor, &amp;amp;min, &amp;amp;sec);
	
	if (hor &amp;gt;= 12) {
		printf(&quot;%d %d %d PM&quot;, hor-12, min, sec);
	}else {
		printf(&quot;%d %d %d AM&quot;, hor, min, sec);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;能否构成三角形&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b, c;
	scanf(&quot;%d %d %d&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c);
	
	if (a+b &amp;gt; c &amp;amp;&amp;amp; a+c &amp;gt; b &amp;amp;&amp;amp; b+c &amp;gt; a) {
		printf(&quot;YES&quot;);
	}else {
		printf(&quot;NO&quot;);
	}
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;找出3个整数居中的整数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int a, b, c;
	scanf(&quot;%d %d %d&quot;, &amp;amp;a, &amp;amp;b, &amp;amp;c);
	
	int res;
	
	if (a &amp;gt; b) {
		if (b &amp;gt; c) {
			res = b;
		}else if (a &amp;gt; c) {
			res = c;
		}else {
			res = a;
		}
	}else if (a &amp;gt; c) {
		res = a;
	}else if (b &amp;gt; c) {
		res = c;
	}else {
		res = b;
	}
	
	printf(&quot;%d&quot;, res);
	
	return 0;
}



&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;学生成绩评定&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int scr;
	scanf(&quot;%d&quot;, &amp;amp;scr);
	
	if (scr &amp;gt; 85) {
		printf(&quot;very good&quot;);
	}else if (scr &amp;lt;= 85 &amp;amp;&amp;amp; scr &amp;gt;= 60) {
		printf(&quot;good&quot;);
	}else {
		printf(&quot;no good&quot;);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求月份对应的英文名称及天数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int mth;
	scanf(&quot;%d&quot;, &amp;amp;mth);
	
	switch ( mth ) {
		case 1:
			printf(&quot;January,31&quot;);
			break;
		
		case 2:
			printf(&quot;February,28/29&quot;);
			break;
			
		case 3:
			printf(&quot;March,31&quot;);
			break;
	
		case 4:
            printf(&quot;April,30&quot;);
            break;

		case 5:
			printf(&quot;May,31&quot;);
			break;

		case 6:
			printf(&quot;June,30&quot;);
			break;

		case 7:
			printf(&quot;July,31&quot;);
			break;

		case 8:
			printf(&quot;August,31&quot;);
			break;

		case 9:
			printf(&quot;September,30&quot;);
			break;

		case 10:
			printf(&quot;October,31&quot;);
			break;

		case 11:
			printf(&quot;November,30&quot;);
			break;

		case 12:
			printf(&quot;December,31&quot;);
			break;	
			
	}
	
	return 0;
	
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;百分制分数转换为等级&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int scr;
	scanf(&quot;%d&quot;, &amp;amp;scr);
	
	int tag = scr;
	scr /= 10;
	
	switch ( scr ) {
		case 10:
		case 9:
			printf(&quot;score=%d,grade:A&quot;, tag);
			break;
			
		case 8:
			printf(&quot;score=%d,grade:B&quot;, tag);
			break;
			
		case 7:
			printf(&quot;score=%d,grade:C&quot;, tag);
			break;
			
		case 6:
			printf(&quot;score=%d,grade:D&quot;, tag);
			break;
			
	    default:
			printf(&quot;score=%d,grade:E&quot;, tag);
			break;
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第五章1&lt;/h2&gt;
&lt;h3&gt;求若干整数的最大值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int max = 0;
	int cnt = 1;
	int num = 0;
	
	scanf(&quot;%d&quot;, &amp;amp;max);
	
	for (cnt = 1; cnt &amp;lt; n; cnt++) {
		scanf(&quot;%d&quot;, &amp;amp;num);
		if (num &amp;gt; max) {
			max = num;
		}
	}
	
    printf(&quot;%d&quot;, max);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;n！&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int num = 0;
	int res = 1;
	int fac = 1;
	
	scanf(&quot;%d&quot;, &amp;amp;num);
	
	while (fac &amp;lt;= num){
		res *= fac;
		fac++;
	}
	
	printf (&quot;%d!=%d&quot;, num, res);
	
	return 0;
} 


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;最大公约数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int num1, num2;
	scanf(&quot;%d %d&quot;, &amp;amp;num1, &amp;amp;num2);
	
	int mask = 0;
	
	while (num2 != 0) {
		mask = num1 % num2;
		num1 = num2;
		num2 = mask;
	}
	
	printf(&quot;%d&quot;, num1);
	
	return 0;
}//解决了1 2的公约数是1的问题


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;最小值和最大值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n = 0;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int first = 0;
	scanf(&quot;%d&quot;, &amp;amp;first);
	
	int max = first;
	int min = first;
	int num = 0;
	int cntmax = 1;
	int cntmin = 1;
	
	for (int cnt = 1; cnt &amp;lt; n; cnt++) {
		scanf(&quot;%d&quot;, &amp;amp;num);
		if (num &amp;gt; max) {
			max = num;
			cntmax = 1;
		}else if (num == max) {
			cntmax++;
		}
		if (num &amp;lt; min) {
			min = num;
			cntmin = 1;
		}else if (num == min) {
			cntmin++;
		}
	}
	
	printf(&quot;%d %d\n%d %d&quot;, min, cntmin, max, cntmax);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;连续因子&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main() {
    long long n;
    scanf(&quot;%lld&quot;, &amp;amp;n);

    long long len = 0;
    long long ans = 0;

    for (long long i = 2; i * i &amp;lt;= n; i++) {
        long long temp = 1;
        long long k = i;
        while (temp * k &amp;lt;= n) {
            temp *= k;
            if (n % temp == 0 &amp;amp;&amp;amp; k - i + 1 &amp;gt; len) {
                len = k - i + 1;
                ans = i;
            }
            k++;
        }
    }

    if (len == 0) {
        printf(&quot;1\n%lld\n&quot;, n);
    } else {
        printf(&quot;%lld\n&quot;, len);
        for (int i = 0; i &amp;lt; len; i++) {
            if (i &amp;gt; 0) printf(&quot;*&quot;);
            printf(&quot;%lld&quot;, ans + i);
        }
        printf(&quot;\n&quot;);
    }

    return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;打印沙漏&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int sum = -1;
	int i = 2;
	
	while (n - sum - i &amp;gt;= 0) {
		sum += i;
		i += 4;
	}
	
	int k = i;
	int j = 1;
	int u = 1;
	
	while (k &amp;gt; 2) {
		
	int t = k / 2;
	int j = u;
	
		while (t &amp;gt; 2) {
			if (t == 3) {
				printf(&quot;*\n&quot;);
			}else {
				printf(&quot;*&quot;);
			}
			t--;
		}
		
		while (j &amp;gt; 0 &amp;amp;&amp;amp; k &amp;gt; 6) {
			printf(&quot; &quot;);
			j--;
		}
		
	k -= 4;
	u += 1;

	}
	
	k = i;
	u -= 3;
	int p = 3;
	int m = 3;
	
	while (u &amp;gt;= 0) {
		
		j = u;
	 	p = m;
	 	
		while (j &amp;gt; 0) {
			printf(&quot; &quot;);
			j--;
		}
		
		while (p &amp;gt; 0) {
			if (p == 1) {
				printf(&quot;*\n&quot;);
			}else {
				printf(&quot;*&quot;);
			}
			p--;
		}
		
		m += 2;
		u -= 1;
	}

	int difference = n - sum;
	
	printf(&quot;%d&quot;, difference);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;念数字&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
    int x;
    scanf(&quot;%d&quot;, &amp;amp;x);
    
    int mask = 1;
    int t = x;
    
    if (x &amp;lt; 0) {
    	printf(&quot;fu &quot;);
    	x = - x;
    	t = - t;
	}
    
	while (t &amp;gt; 9) {
    	t /= 10;
    	mask *= 10;
	}
	
	do {
		int d = x / mask;
		
		switch (d) {
			case 0:
				printf(&quot;ling&quot;);
				break;
			case 1:
				printf(&quot;yi&quot;);
				break;
			case 2:
				printf(&quot;er&quot;);
				break;
			case 3:
				printf(&quot;san&quot;);
				break;
			case 4:
				printf(&quot;si&quot;);
				break;
			case 5:
				printf(&quot;wu&quot;);
				break;
			case 6:
				printf(&quot;liu&quot;);
				break;
			case 7:
				printf(&quot;qi&quot;);
				break;
			case 8:
				printf(&quot;ba&quot;);
				break;
			case 9:
				printf(&quot;jiu&quot;);
				break;								
		}
		
		x %= mask;
		mask /= 10;
		
		if (mask &amp;gt; 0) {
			printf(&quot; &quot;);
		}
		
	}while (mask &amp;gt; 0);

	return 0;	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;N个有理数求和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#define ll long long

ll abss(ll x) { return x &amp;lt; 0 ? -x : x; }

ll gcd(ll a, ll b) {
    if (a &amp;lt; 0) a = -a;
    if (b &amp;lt; 0) b = -b;
    while (b != 0) {
        ll t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    int n;
    if (scanf(&quot;%d&quot;, &amp;amp;n) != 1) return 0;

    ll num = 0;
    ll den = 1;

    for (int i = 0; i &amp;lt; n; ++i) {
        ll a, b;
        scanf(&quot;%lld/%lld&quot;, &amp;amp;a, &amp;amp;b);

        ll g = gcd(den, b);
        ll den1 = den / g;
        ll b1 = b / g;

        ll new_num = num * b1 + a * den1;
        ll new_den = den * b1;

        ll g2 = gcd(abss(new_num), new_den);
        new_num /= g2;
        new_den /= g2;

        if (new_den &amp;lt; 0) { new_den = -new_den; new_num = -new_num; }

        num = new_num;
        den = new_den;
    }

    ll integer = num / den;
    ll remainder = num % den;

    if (remainder == 0) {
        printf(&quot;%lld&quot;, integer);
        putchar(&apos;\n&apos;);
    } else {
        if (integer != 0) {
            printf(&quot;%lld&quot;, integer);
            putchar(&apos; &apos;);
            printf(&quot;%lld&quot;, remainder);
            putchar(&apos;/&apos;);
            printf(&quot;%lld&quot;, den);
            putchar(&apos;\n&apos;);
        } else {
            printf(&quot;%lld&quot;, remainder);
            putchar(&apos;/&apos;);
            printf(&quot;%lld&quot;, den);
            putchar(&apos;\n&apos;);
        }
    }

    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;画方块&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

int main()
{
	double n;
	char c;
	scanf(&quot;%lf %c&quot;, &amp;amp;n, &amp;amp;c);
	
	int cnt = 0;
	double mask = 0.0;
	int tag = round (n / 2);
	
	while (cnt &amp;lt;= n) {
		cnt++;
		printf(&quot;%c&quot;, c);
		if (cnt == n) {
			printf(&quot;\n&quot;);
			cnt = 0;
			mask ++;
			if (mask == tag) {
				break;
			}
		} 
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;守形数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int min, max;
	scanf(&quot;%d %d&quot;, &amp;amp;min, &amp;amp;max);
	
	int tag = min;
	int mask = 10;
	int test = 0;
	int isfirst = 1;
	
	for (tag = min; tag &amp;lt;= max; tag++) {
		int t = tag * tag;
		int p = tag;
	    mask = 1;
		while (p &amp;gt; 0) {
			p /= 10;
			mask *= 10;
		}
		int cur = t % mask;
		if (cur == tag) {
			if (isfirst == 1) {
				printf(&quot;%d&quot;, tag);
				test = 1;
				isfirst = 0;
			}else{
			printf(&quot; %d&quot;, tag);
		}
	}
	}
	
	if (test == 0) {
		printf(&quot;No exist&quot;);
	}

	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;含数字5且是3的倍数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int m, n;
	scanf(&quot;%d %d&quot;, &amp;amp;m, &amp;amp;n);
	
	int i = m;
	int tag = 1;
	
	while (i &amp;lt;= n) {
		
		int j = 1;
		int k = i;
		
		int mask = 0;
		
		while (k &amp;gt; 0) {
			int num = k % 10;
			if (num == 5) {
				mask = 1;
				break;
			}else {
				k /= 10;
			}
		}
		
		if (i % 3 == 0 &amp;amp;&amp;amp; mask == 1) {
			if (tag == 1) {
				printf(&quot;%d&quot;, i);
				tag = 0;
			}else {
				printf(&quot; %d&quot;, i);
			}
		}
		
		i++;
		
	}
	
	if (tag == 1) {
		printf(&quot;No exist&quot;);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;小球自由落体&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int cnt = 0;
	double res = 0.0;
	double h = 100.0;
	int tag = 1;
	
	for (cnt = 0; cnt&amp;lt; n; cnt++) {
		if (tag == 1) {
			res += 100;
			tag = 0;
		}else {
			h /= 2;
		    res += h*2;
		    
		}
	}
		  
	printf(&quot;%lf %lf&quot;, res, h/2);

    return 0;

}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;鸡兔同笼&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int h, f;
	scanf(&quot;%d %d&quot;, &amp;amp;h, &amp;amp;f);
	
	int c = 0;
	int r = 0;
	int res = 0;
	
    for (r = 0; r&amp;lt;= h; r++) {
    	c = h - r;
    	if (4*r + 2* c == f) {
    		res = 1;
    		break;
		}
	}
    
	if (res == 1) {
		printf (&quot;%d %d&quot;, c, r);
	}else {
		printf(&quot;Error&quot;);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算π的近似值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int cnt = 0;
	double res = 0.0;
	int i = 1;
	int sign = 1;
	
	for (cnt = 0; cnt &amp;lt; 2*n; cnt++) {
		res += sign * 1.0 / i;
		i += 2;
		sign = -sign;
	}
	
	printf(&quot;%lf&quot;, res*4.0);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;“韩信点兵”数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int min, max;
	scanf(&quot;%d %d&quot;, &amp;amp;min, &amp;amp;max);
	
	int res = 0;
	int cnt = 0;
	int tag = 1;
	
	for (res = min; res &amp;lt;= max ; res++) {
		if (res % 3 == 2 &amp;amp;&amp;amp; res % 5 == 3 &amp;amp;&amp;amp; res % 7 == 4) {
                if ( tag == 1) {
                    printf(&quot;%d&quot;, res);
                    tag = 0;
                    cnt++;
                }else {
                cnt++;
                printf(&quot; %d&quot;, res);
			}
		}
		
	}
	
	if (cnt == 0) {
		printf(&quot;total=0&quot;);
	}else {
		printf(&quot;\ntotal=%d&quot;, cnt);
    }
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;祖孙年龄&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int x, y1, y2, y3;
	scanf(&quot;%d %d %d %d&quot;, &amp;amp;x, &amp;amp;y1, &amp;amp;y2, &amp;amp;y3);
	
	int res = x - y1 - y2 - y3;
	
	if (res % 2 == 0) {
		printf(&quot;%d&quot;, res / 2 );
	}else {
		printf(&quot;%d&quot;, (res + 1) / 2 );
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;输出Fibonacci数列的前n项&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int i = 1;
	int j = 0;
	int k;
	int cnt;
	int p = 1;
	
	for (cnt = 0; cnt &amp;lt; n; cnt++) { 
		printf(&quot;%10d&quot;, i);
		if (p % 5 == 0 &amp;amp;&amp;amp; p!= 0) {
			printf(&quot;\n&quot;);
		}
		k = i;
		i = j + i;
		j = k;
		p++;
	}
	
	return 0;
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;菱形图案&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	n += 1;
	
	int cnt = 1;
	int CNT = 1;
	
	for (int s = n - 1; s &amp;gt; 0; s--) {
		for (int cnt_s = s; cnt_s &amp;gt; 1; cnt_s--) {
			printf(&quot; &quot;);
		}
		
		int cnt_q = 1;
		
		for ( ; cnt_q &amp;lt;= cnt; cnt_q++) {
			if (cnt_q == cnt) {
				printf(&quot;*\n&quot;);
			}else {
				printf(&quot;*&quot;);
			}
		}
	
		cnt += 2;
	}
	
	int CNT_S = 1;
	int mask = 0;
	int tag = 1;
	
	for (int S = n - 2; S &amp;gt; 0; S--) {		
		int cnt_S = 1;
		for (int cnt_S = 1 ; cnt_S &amp;lt;= CNT_S; cnt_S++) {
			mask++;
			if (cnt_S == 1 &amp;amp;&amp;amp; tag == 0) {
				printf(&quot;\n &quot;);
			}else {
				printf(&quot; &quot;);
			}	
		}

		int cnt_Q = 2 * (n - 1) - 3;
		
		for ( ; cnt_Q &amp;gt; 0; cnt_Q--) {
			if (cnt_Q == 1) {
				printf(&quot;*&quot;);
			}else {
				printf(&quot;*&quot;);
			}
		} 
		
		CNT += 1;
		n--;
		CNT_S++;
		tag = 0;
	}
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算某分数序列的前n项之和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	double sum = 0.0;
    int cnt = 0;
	double i = 2.0;
	double j = 1.0;
	double k = 2.0;
	
	for (cnt = 0; cnt &amp;lt; n; cnt++) {
		sum += i / j;
		k = i;
		i += j;
		j = k; 
	}
	
	printf(&quot;%lf&quot;, sum);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;素数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int num;
	int i;
	int isprime = 1;
	
	scanf(&quot;%d&quot;, &amp;amp;num);
	
	if (num == 1) {
		printf(&quot;NO&quot;);
		goto final;
	}else { 
	
	for (i = 2; i &amp;lt; num; i++){
		if (num % i == 0){
			isprime = 0;
			break;
		}
		
	}
	if (isprime == 1) {
		printf(&quot;YES&quot;);
	}else {
	    printf(&quot;NO&quot;); 
	}
}
final:
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第五章2&lt;/h2&gt;
&lt;h3&gt;寻找250&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{	
    int result = 1;
    int cnt = 0;

	do {
		int num = 0;
		result = scanf(&quot;%d&quot;, &amp;amp;num);
		cnt++;
		if (num == 250) {
			break;
		}
	}while (result == 1);
	
	printf(&quot;%d&quot;, cnt);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;计算阶乘和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int cnt = 1;
	int s = 0;
	
	do {
		int count = 1;
		int cur = 1;
		while (count &amp;lt;= cnt) {
			cur = count * cur;
			count++; 
			} 
		s += cur;
		cnt++;
	} while (cnt &amp;lt;= n);
	
	printf(&quot;%d&quot;, s);
	
	return 0;
} 


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;整除光棍&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;

int main()
{	    
	int x;
	scanf(&quot;%d&quot;, &amp;amp;x);		
	int count = 1;   
	int a = 1;	    

	while (a &amp;lt; x) {			
		a = a * 10 + 1;		
		count++;
	}
	printf(&quot;%d&quot;, a / x);
		
	int t = a % x;  
	
	while (t != 0) {			//利用循环将商从高到低位依次输出，直到余数为0。
		t = t * 10 + 1;		
		printf(&quot;%d&quot;, t / x);
		count++;
		t %= x;
	}
	printf(&quot; %d&quot;, count);

	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求幂级数展开的部分和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	double x;
	scanf(&quot;%lf&quot;, &amp;amp;x);
	
	double res = 1;
	int t = x;
	double temp = 1;
	int cnt = 1;
	
	while (temp &amp;gt;= 0.000001) {
		temp = temp * x / cnt;
		res += temp;
		cnt++;
	}
	
	printf(&quot;%.5f&quot;, res);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求奇数和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int num = 1;
	int temp = 0;
	int res = 0;
	
	while (num &amp;gt; 0) {
		scanf(&quot;%d&quot;, &amp;amp;num);
		if (num &amp;gt; 0) {
			temp = num % 2;
			if (temp != 0) {
				res += num;
		    }	
		}
		
	}
	
	printf(&quot;%d&quot;, res);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;猴子吃桃问题&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int res = 1;
	
	for (int cnt = 1; cnt &amp;lt; n; cnt++) {
		res = (res + 1) * 2;
	}
	
	printf(&quot;%d&quot;, res);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;水仙花数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int first = 1;
	int i = 1;
	
	while (i &amp;lt; n) {
		first *= 10;
		i++;
	}
	
    i = first;
    
    while (i &amp;lt; first * 10) {
    	int t = i;
    	int sum = 0;
    	
    	do {
    		int d = t % 10;
    		t /= 10;
    		int p = d;
    		int j = 1;
    		
    		while (j &amp;lt; n) {
    			p *= d;
    			j++;
			}
			sum += p;
			
		} while (t &amp;gt; 0);
		
		if (sum == i) {
			printf(&quot;%d\n&quot;, i);
		}
    	
    	i++;
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;兔子繁衍问题&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    int N;
    scanf(&quot;%d&quot;, &amp;amp;N);

    if (N &amp;lt;= 1) {
        printf(&quot;1\n&quot;);
        return 0;
    }

    int a = 1;
    int b = 1;
    int month = 2;

    while (b &amp;lt; N) {
        int c = a + b;
        a = b;
        b = c;
        month++;
    }

    printf(&quot;%d\n&quot;, month);
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;黑洞数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int num = 0;
	scanf(&quot;%d&quot;, &amp;amp;num);
	
	int x = num;
	int temp = 0;
	int X = 0;
	int cnt = 1;
	
	do {
		int c = 0;
		int b = 0;
		int a = 0;
		
		c = x / 100;
		b = x / 10 - c * 10;
		a = x - c * 100 - b * 10;
		
		if (a &amp;gt; b) {
			if (b &amp;gt; c) {
				temp = a * 100 + b * 10 + c;
				x = c * 100 + b * 10 + a;
			}else if (a &amp;gt; c) { 
				temp = a * 100 + c * 10 + b;
				x = b * 100 + c * 10 + a;
			}else {
				temp = c * 100 + a * 10 + b;
				x = b * 100 + a * 10 + c;
			}
		}else if (a &amp;gt; c) {
			temp = b * 100 + a * 10 + c;
			x = c * 100 + a * 10 + b;
		}else if (b &amp;gt; c) {
			temp = b * 100 + c * 10 + a;
			x = a * 100 + c * 10 + b;
		}else {
			temp = c * 100 + b * 10 + a;
			x = a * 100 + b * 10 + c;
		}
	  
	    int mask = temp - x;
	    if (mask == 495) {
	    	printf(&quot;%d: %d - %d = %d&quot;, cnt, temp, x, mask);
		}else {
	        printf(&quot;%d: %d - %d = %d\n&quot;, cnt, temp, x, mask);
 		}
		X = x;
		x = mask;
		cnt++;
		
	}while (temp - X != 495);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;输出三角形字符阵列&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	char chr = &apos;A&apos;;
	int cnt = 0;
	int N = n;
	int mask = 1;
	
	while (cnt &amp;lt;= n) {
		
		if (N == 1 &amp;amp;&amp;amp; mask == 1) {
			printf(&quot;%c\n&quot;, chr);	
		}else if (N &amp;gt; 1 &amp;amp;&amp;amp; mask == 1) {
			printf(&quot;%c &quot;, chr);	
		}else if (N == 1 &amp;amp;&amp;amp; mask == 0) {
			printf(&quot;%c&quot;, chr);
		}
		
		chr++;
		N--;
		
		if (N == 0) {
			n -= 1;
			N = n;
			cnt = 0;
		} 
		
		if (N == 1 &amp;amp;&amp;amp; n == 1) {
			mask = 0;
		} 
		
		cnt++;
		
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求整数的位数及各位数字之和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    long long N;
    scanf(&quot;%lld&quot;, &amp;amp;N);

    int digits = 0;
    int sum = 0; 
    long long temp = N;

    while (temp &amp;gt; 0) {
        sum += temp % 10; 
        temp /= 10; 
        digits++;
    }

    printf(&quot;%d %d\n&quot;, digits, sum);
    return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;特殊a串数列求和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int a, n;
	scanf(&quot;%d %d&quot;, &amp;amp;a, &amp;amp;n);
	
	int temp = a;
	int res = a;
	
	for (int cnt = 0; cnt &amp;lt; n - 1; cnt++) {
		temp = temp * 10 + a;
		res += temp;
		
	}
	
	printf(&quot;%d&quot;, res);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;验证“哥德巴赫猜想”&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	long int n;
	scanf(&quot;%ld&quot;, &amp;amp;n);
	
	long int b = 0;
	long int num1 = 0;
	long int num2 = 0;
	
	for (long int t = 2; t &amp;lt;= n; t++) {
		int isPrime = 1;
		
		for (long int i = 2; i * i &amp;lt; t; i++) {
			if (t % i == 0 &amp;amp;&amp;amp; t != 2) {
				isPrime = 0;
				break;
			}
		}
		
		if (isPrime == 1) {
			num1 = t;
			b = n - t;
		}
		
		int isprime = 1;
		
		for (long int j = 2; j * j &amp;lt; b; j++) {
			if (b % j == 0 &amp;amp;&amp;amp; b != 2) {
				isprime = 0;
				break;
			}
		}
		
		if (isprime == 1) {
			num2 = b;
			break;
		}
	}
	
	printf(&quot;%ld = %ld + %ld&quot;, n, num1, num2);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;换硬币&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int x;
	scanf(&quot;%d&quot;, &amp;amp;x);
	
	int one;
	int two;
	int five;
	int mask = 0;
	
	for (five = x / 5; five != 0; five--) {
		for (two = x / 2; two != 0; two--) {
			for (one = x - 1; one != 0; one--) {
				if (one + two * 2 + five * 5 == x) {
					int cnt = one + two + five;
					printf(&quot;fen5:%d, fen2:%d, fen1:%d, total:%d\n&quot;, five, two, one, cnt);
					mask++;
				}
			}
		}
	}
	
	printf(&quot;count = %d&quot;, mask);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;统计素数并求和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () 
{
	int m, n;
	scanf(&quot;%d %d&quot;, &amp;amp;m, &amp;amp;n);
	
	int cnt = 0;
	int res = 0;
	
	if (m &amp;lt; 2) {
		m = 2;
	}
	
	for (int t = m; t &amp;lt;= n; t++) {
		int isPrime = 1;
		for (int x = 2; x &amp;lt; t; x++) {
			int rem = t % x;
			if (rem == 0) {
				isPrime = 0;
				break;
			}
		}
		if (isPrime == 1) {
			res += t;
			cnt++;
		}
	}
	
	printf(&quot;%d %d&quot;, cnt, res);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求e的近似值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	double e = 1;
	double res = 1;
	
	for (int num = 1; num &amp;lt;= n; num++) {
		res = 1;
		for (int t = 1; t &amp;lt;= num; t++) {
			res *= t;
		}
		e += 1.0 / res;
	}
	
	printf(&quot;%.8f&quot;, e);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求平方与倒数序列的部分和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	double m, n;
	scanf(&quot;%lf %lf&quot;, &amp;amp;m, &amp;amp;n);
	
	double s = 0;
	
	for ( ; m &amp;lt;= n; m++) {
		s += m * m + 1.0 / m;
	}
	
	printf(&quot;%.6f&quot;, s);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求组合数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n, m;
	scanf(&quot;%d %d&quot;, &amp;amp;n, &amp;amp;m);
	
	double N = 1;
	
	for (int numN = 1; numN &amp;lt;= n; numN++) {
		N *= numN;
	}
	
	double M = 1;
	
	for (int numM = 1; numM &amp;lt;= m; numM++) {
		M *= numM;
	}
	
	double C = 1;
	
	for (int numC = 1; numC &amp;lt;= m - n; numC++) {
		C *= numC;
	}
	
	double res = M / N / C;
	
	printf(&quot;%.0f&quot;, res);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求简单交错序列前N项和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int den = 1;
	double s = 0;
	int sign = 1; 
	
	for (int cnt = 0; cnt &amp;lt; n; cnt++) {
		s += sign * 1.0 / den;
		den += 3;
		sign = -sign;
	}
	
	printf(&quot;%.4f&quot;, s);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;最佳情侣身高差&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
    char x;
	double h;
	int cnt = 0;
	
	do {
	    scanf(&quot; %c&quot;, &amp;amp;x);
		scanf(&quot;%lf&quot;, &amp;amp;h);
		if (x == &apos;M&apos;) {
			h /= 1.09;
		}else {
			h *= 1.09;
		}
		
		printf(&quot;%.2f\n&quot;, h);
		cnt++;
    } while (cnt &amp;lt; n);	
    
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>C语言作业答案(下)</title><link>https://blog.everlasting.xin/posts/c_homework_part2/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/c_homework_part2/</guid><description>整理 C 语言作业下半部分的参考答案，方便复习与查阅。</description><pubDate>Wed, 07 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;C语言作业答案(下)&lt;/h1&gt;
&lt;h2&gt;第六章1&lt;/h2&gt;
&lt;h3&gt;逆序输出输入的整数&lt;/h3&gt;
&lt;p&gt;&amp;lt;!-- more --&amp;gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num [n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;num [i]);
	}
	
	int mask = 1;
	
	for (int j = n - 1; j &amp;gt;= 0; j--) {
		if (mask == 1) {
			printf(&quot;%d&quot;, num [j]);
			mask = 0;
		}else {
			printf(&quot; %d&quot;, num [j]);
		}
	}
	
	return 0;
	
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;统计各大写字母的个数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char s[10000];
	scanf(&quot;%[^\n]&quot;, s);
	
	int cnt[26] = {0};
	
	for (int i = 0; s[i] != &apos;\0&apos;; i++) {
		if (s[i] &amp;gt;= &apos;A&apos; &amp;amp;&amp;amp; s[i] &amp;lt;= &apos;Z&apos;) {
			cnt[s[i] - &apos;A&apos;]++;
		}
	}
	
	for (int i = 0; i &amp;lt; 26; i++) {
		printf(&quot;%c(%d)&quot;, &apos;A&apos; + i, cnt[i]);
		if ((i + 1) % 5 == 0) {
			printf(&quot;\n&quot;);
		}
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;输出斐波那契数列的前n项&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num [n];

	for (int i = 0; i &amp;lt; n; i++) {
		if (i == 0 || i == 1) {
			num [i] = 1; 
		}else {
			num [i] = num [i - 1] + num [i - 2];
		}	
	}
	
	int mask = 1;
		
	for(int j = 0; j &amp;lt; n; j++) {
		if (mask % 5 == 0) {
			if (mask == n) {
				printf(&quot;%10d&quot;, num [j]);
			}else {
				printf(&quot;%10d\n&quot;, num [j]);
				mask++;
			}
		}else {
			printf(&quot;%10d&quot;, num [j]);
			mask++;
		}
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;约瑟夫问题&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
	int n, m, s;
	scanf(&quot;%d %d %d&quot;, &amp;amp;n, &amp;amp;m, &amp;amp;s);
	
	int num[n + 1];
	num[0] = 0;
	
	for (int i = 1; i &amp;lt;= n; i++) {
		num[i] = i;
	}
	
	int i = s;
	int t = n;
	
	while (t &amp;gt; 0) {
		int cnt = 0;
		while (cnt &amp;lt; m) {
			if (num[i] != 0) {
				cnt++;
			}
			
			if (cnt &amp;lt; m) {
				i++;
				if (i &amp;gt; n) {
					i = 1;
				}
			}
		}
		printf(&quot;%3d&quot;, num[i]);
		num[i] = 0;
		t--;
		
		do {
			i++;
			if (i &amp;gt; n) {
				i = 1;
			}
		}while (num[i] == 0 &amp;amp;&amp;amp; t &amp;gt; 0);
		
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;奇数阶幻方问题&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int s[n][n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			s[i][j] = 0;
		}
	}
	
	int i = 0;
	int j = (n - 1) / 2;
	
	for (int k = 1; k &amp;lt;= n * n; k++) {
		s[i][j] = k;
		int I = i;
		int J = j;
		i -= 1;
		j += 1;

		if (i &amp;lt; 0) {
			i = n - 1;
		}
		if (j &amp;gt; n - 1) {
			j = 0;	
		}
		if (s[i][j] != 0) {
			i = I + 1;
			j = J;
		}
		
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			printf(&quot;%4d&quot;, s[i][j]);
			if (j == n - 1) {
				printf(&quot;\n&quot;);
			}
		}
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;统计学生的总分以及各课程的平均分&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n, m;
	scanf(&quot;%d %d&quot;, &amp;amp;n, &amp;amp;m);
	
	char name[n][100];
	int grade[n][m];
	
	int sum[n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		sum[i] = 0;
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%s&quot;, name[i]);
		for (int j = 0; j &amp;lt; m; j++) {
			scanf(&quot;%d&quot;, &amp;amp;grade[i][j]);
			sum[i] += grade[i][j];
		}
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		printf(&quot;%-8s&quot;, name[i]);
		printf(&quot;%6d&quot;, sum[i]);
		for (int j = 0; j &amp;lt; m; j++) {
			printf(&quot;%6d&quot;, grade[i][j]);
		}
		printf(&quot;\n&quot;);
	}
	
	double aver[m];
	
	for (int i = 0; i &amp;lt; m; i++) {
		aver[i] = 0;
	}
	
	for (int i = 0; i &amp;lt; m; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			aver[i] += grade[j][i];
		}
		aver[i] /= n;
	}
	
	printf(&quot;average score:&quot;);
	
	for (int i = 0; i &amp;lt; m; i++) {
		printf(&quot;%6.1f&quot;, aver[i]);
 	}	
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;统计学生成绩的最高最低分以及超过平均分的人数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () 
{
	
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int grade[n];
	double aver = 0;
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;grade[i]);
		aver += grade[i];
	}
	
	aver /= n;
	
	int cnt = 0;
	
	for (int i = 0; i &amp;lt; n; i++) {
		if (grade[i] &amp;gt; aver) {
			cnt++;
		}
	}
	
	int min = grade[0];
	
	for (int i = 1; i &amp;lt; n; i++) {
		if (grade[i] &amp;lt; min) {
			min = grade[i];
		}
	}
	
	int max = grade[0];
	
	for (int i = 1; i &amp;lt; n; i++) {
		if (grade[i] &amp;gt; max) {
			max = grade[i];
		}
	}
	
	printf(&quot;%d %d %d&quot;, max, min, cnt);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;进制转换&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char str[100];
	
	int num = 0;
	int i = 0;
	char c;
	
	while ((c = getchar()) != &apos;#&apos;) {
		if ((c &amp;gt;= &apos;0&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;9&apos;) || (c &amp;gt;= &apos;A&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;F&apos;) || (c &amp;gt;= &apos;a&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;f&apos;)) {
			str[i++] = c;
			num *= 16;
			if (c &amp;gt;= &apos;0&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;9&apos;) {
                num += c - &apos;0&apos;;
            }else if (c &amp;gt;= &apos;A&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;F&apos;) {
                num += c - &apos;A&apos; + 10;
            }else if (c &amp;gt;= &apos;a&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;f&apos;) {
            	num += c - &apos;a&apos; + 10;
			}
		}
	}
	
	str[i] = &apos;\0&apos;;
	
	printf(&quot;String:%s\n&quot;, str);	
	printf(&quot;number=%d&quot;, num);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求最大字符串&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	getchar();
	
	char str[n][100];
	
	for (int i = 0; i &amp;lt; n; i++) {
		gets(str[i]);
	}
	
	int maxI = 0;
	
	for (int i = 1; i &amp;lt; n; i++) {
		if (strcmp(str[i], str[maxI]) &amp;gt; 0) {
			maxI = i;
		}
	}
	
	printf(&quot;%s&quot;, str[maxI]);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;字符串首尾相连&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() {
    char str1[101],str2[101];
    int i,j;

    gets(str1);
    gets(str2);
  // Here is your code
    i = 0;
    while (str1[i] != &apos;\0&apos; &amp;amp;&amp;amp; str1[i] != &apos;\n&apos;) {
        i++;
    }
    str1[i] = &apos;\0&apos;; 
    
    j = 0;
	while (str2[j] != &apos;\0&apos; &amp;amp;&amp;amp; str2[j] != &apos;\n&apos;) {
        j++;
    }
    str2[j] = &apos;\0&apos;;
    
	for (int k = 0; k &amp;lt; j; k++) {
        str1[i] = str2[k];
        i++;
    }
    str1[i] = &apos;\0&apos;;

  puts(str1);
  return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;统计各数字出现的次数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char c;
	int num[10] = {0};
	
	while (c != &apos;!&apos;){
		scanf(&quot;%c&quot;, &amp;amp;c);
		if (c &amp;gt;= &apos;0&apos; &amp;amp;&amp;amp; c &amp;lt;= &apos;9&apos;) {
			num[c - &apos;0&apos;]++;
		}
	}
	
	for (int i = 0; i &amp;lt; 10; i++) {
		if (i == 9) {
			printf(&quot;The character %d appears %d times&quot;, i, num[i]);
		}else {
			printf(&quot;The character %d appears %d times\n&quot;, i, num[i]);
		}
	}
	
	return 0;
	
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;找出二维数组中的最小元素&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int m, n;
	scanf(&quot;%d %d&quot;, &amp;amp;m, &amp;amp;n);
	
	int a[m][n];
	
	for (int i = 0; i &amp;lt; m; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			scanf(&quot;%d&quot;, &amp;amp;a[i][j]);
		}
	}
	
	printf(&quot;before:\n&quot;);
	
	for (int i = 0; i &amp;lt; m; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			printf(&quot;%4d&quot;, a[i][j]);
		}
		printf(&quot;\n&quot;);
	}
	
	printf(&quot;after:\n&quot;);
	
	int min =a[0][0];
	
	int I = 0;
	int J = 0;
	
	for (int i = 0; i &amp;lt; m; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			if (a[i][j] &amp;lt; min) {
				min = a[i][j];
				I = i;
				J = j;
			}
		}
	}
	
	for (int j = 0; j &amp;lt; n; j++) {
		int t = a[m - 1][j];
		a[m - 1][j] = a[I][j];
		a[I][j] = t;
	}
	
	int mask = 0;
	
	for (int i = 0; i &amp;lt; m; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			printf(&quot;%4d&quot;, a[i][j]);
		}
		if (i != m - 1) {
			printf(&quot;\n&quot;);
		}
	}
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;矩阵转置&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n, m;
	scanf(&quot;%d %d&quot;, &amp;amp;n, &amp;amp;m);
	
	int a[n][m];
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; m; j++) {
			scanf(&quot;%d&quot;, &amp;amp;a[i][j]);
		}
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; m; j++) {
			if (j == m - 1) {
				printf(&quot;%d&quot;, a[i][j]);
			}else {
				printf(&quot;%d &quot;, a[i][j]);
			} 
		}
		printf(&quot;\n&quot;);
	}
	
	int b[m][n];
	
	for (int i = 0; i &amp;lt; m; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			b[i][j] = a[j][i];
			if (j == n - 1) {
				printf(&quot;%d&quot;, b[i][j]);
			}else {
				printf(&quot;%d &quot;, b[i][j]);
			} 
		}
		printf(&quot;\n&quot;);
	}	
	
	return 0;
		
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;二分查找&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num[n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;num[i]);
	}
	
	int res;
	scanf(&quot;%d&quot;, &amp;amp;res);
	
	int a = 0;
	int b = n - 1;
	
	int mask = 0;
	
	while (a &amp;lt;= b) {
		
		int mid = a + (b - a) / 2;
		
		if (num[mid] == res) {
			printf(&quot;%d&quot;, mid);
			mask = 1;
			break;
		}else if (num[mid] &amp;lt; res) {
			a = mid + 1;
		}else {
			b = mid - 1;
		}
	}
	
	if (mask == 0) {
		printf(&quot;Not found&quot;);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;冒泡排序&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num[100];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;num[i]);
	}
	
	for (int i = 0; i &amp;lt; n - 1; i++) {
		for (int j = 0; j &amp;lt; n - 1 - i; j++) {
			if (num[j] &amp;gt; num[j + 1]) {
				int t = num[j];
				num[j] = num[j + 1];
				num[j + 1] = t;
			}
		}
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		printf(&quot;%d&quot;, num[i]);
		if (i != n - 1) {
			printf(&quot; &quot;);
		} 
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第六章2&lt;/h2&gt;
&lt;h3&gt;大写改小写&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char ch;
	while (scanf(&quot;%c&quot;, &amp;amp;ch) != EOF &amp;amp;&amp;amp; ch != &apos;\n&apos;) {
		if (ch &amp;gt;= &apos;A&apos; &amp;amp;&amp;amp; ch &amp;lt;= &apos;Z&apos;) {
			ch += 32;
		}
		putchar(ch);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;串比较&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char str1[101];
	gets(str1);
	
	char str2[101];
	gets(str2);
	
	int i = 0;
	
	while (str1[i] != &apos;\0&apos; &amp;amp;&amp;amp; str2[i] != &apos;\0&apos; &amp;amp;&amp;amp; str1[i] == str2[i]) {
		i++;
	}
	
	printf(&quot;%d&quot;, str1[i] - str2[i]);
	
	return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;串复制&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() {
	char str1[101],str2[101];
	int i;
	gets(str1);
	// Please fill this blank
	for (i = 0; str1[i] != &apos;\0&apos;; i++) {
		str2[i] = str1[i]; 
	}
	str2[i] = &apos;\0&apos;;
	
	puts(str2);
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;逆向输出字符串&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () 
{
	char str1[101],str2[101];
	int i,j;
	gets(str1);
	// Please fill this blank
	int l = 0;
	while (str1[l] != &apos;\0&apos;) {
		l++;
	}
	for (i = 0, j = l - 1; j &amp;gt;= 0; i++, j--) {
		str2[i] = str1[j];
	}
	
	str2[l] = &apos;\0&apos;;
	
	puts(str2);
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;对方阵做统计处理&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void Traverse(int n, int s[n][n])
{
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			scanf(&quot;%d&quot;, &amp;amp;s[i][j]);
		}
	}
}

int sumD(int n, int s[n][n])
{
	int sum = 0;
	
	for (int i = 0; i &amp;lt; n; i++) {
		sum += s[i][i];
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		sum += s[n - 1 - i][i];
	}
	
	if (n % 2 != 0) {
		sum -= s[(n - 1) / 2][(n - 1) / 2];
	}
	
	return sum;
	
}

int multiple(int n, int s[n][n])
{
	int m = 1;
	
	for (int i = 0; i &amp;lt; n; i += 2) {
		m *= s[i][i]; 
	}
	
	for (int j = 0; j &amp;lt; n; j += 2) {
		if ((n - 1 - j) % 2 == 0) {
			m *= s[n - 1 - j][j];
		} 
	}
	
	return m;
	
}

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int s[n][n];
	Traverse(n, s);
	
	printf(&quot;%d %d\n&quot;, sumD(n, s), multiple(n,s));
	
	int p[n][n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			p[j][n - 1 - i] = s[i][j];
		}
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			printf(&quot;%d&quot;, p[i][j]);
			if (j &amp;lt; n - 1) {
				printf(&quot; &quot;);
			}
		}
		if (i &amp;lt; n - 1) {
			printf(&quot;\n&quot;);
		}
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;兔子和狐狸&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () 
{
	int n, m;
	scanf(&quot;%d %d&quot;, &amp;amp;n, &amp;amp;m);
	
	int h[n + 1];
	
	for (int i = 0; i &amp;lt;= n; i++) {
		h[i] = 1;
	}
	
	h[0] = 0;
	h[1] = 0;
	
	int i = 2;
	int j = 1;
	int s = 1;
	
	while (s &amp;lt;= m * n) {
		j += i;
		s += i;
		i++;
		if (s &amp;gt; m * n) {
			break;
		}
		if (j &amp;gt; n) {
			j %= n;
			if (j == 0) {
				j = n;
			}
		}
		h[j] = 0;
	}
	
	int mask = 1;
	
	for (int i = 0; i &amp;lt;= n; i++) {
		if (h[i] == 1) {
			if (mask == 1) {
				printf(&quot;%d&quot;, i);
				mask = 0;
			}else {
				printf(&quot; %d&quot;, i);
			}
		}
	}
	
	if (mask == 1) {
		printf(&quot;No choice&quot;);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;删除字符串中指定字符&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char str[101];
	gets(str);
	
	char ch;
	scanf(&quot;%c&quot;, &amp;amp;ch);
	
	int j = 0;
	
	for (int i = 0; str[i] != &apos;\0&apos;; i++) {
		if (str[i] != ch) {
			str[j++] = str[i];
		}
	}
	str[j] = &apos;\0&apos;;
	
	printf(&quot;%s&quot;, str);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;奇偶数分开排序&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void sorting (int num[], int n) 
{
	for (int i = n - 1; i &amp;gt; 0; i--) {
		int tag = i;
		for (int j = i - 1; j &amp;gt;= 0; j--) {
			if (num[tag] &amp;lt; num[j]) {
				tag = j;
			}
		}
		int t = num[i];
		num[i] = num[tag];
		num[tag] = t;
	}
}

void print (int num[], int n) 
{
	int mask = 1;
	
	for (int i = 0; i &amp;lt; n; i++) {
		if (mask == 1) {
			printf(&quot;%d&quot;, num[i]);
			mask = 0;
		}else {
			printf(&quot; %d&quot;, num[i]);
		}
	}
}

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num[n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;num[i]);
	}
	
	int odd[n];
	int even[n];
	
	int cnt1 = 0;
	int cnt2 = 0;
	
	for (int i = 0; i &amp;lt; n; i++) {
		if (num[i] % 2 == 1) {
			odd[cnt1] = num[i];
			cnt1++;
		}else {
			even[cnt2] = num[i];
			cnt2++;
		}
	}
	
	sorting(odd, cnt1);
	sorting(even, cnt2);
	
	print(odd, cnt1);
	printf(&quot; &quot;);
	print(even, cnt2);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;选择排序&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num[n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;num[i]);
	}
	
	for (int i = n - 1; i &amp;gt; 0; i--) {
		int tag = i;
		for (int j = i - 1; j &amp;gt;= 0; j--) {
			if (num[tag] &amp;lt; num[j]) {
				tag = j;
			}
		}
		int t = num[i];
		num[i] = num[tag];
		num[tag] = t;
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		printf(&quot;%d &quot;, num[i]);
	}
	
	return 0;
	
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;杨辉三角形&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    int n;
    scanf(&quot;%d&quot;, &amp;amp;n);
    int a[31][31] = {0};
    
    // 构造杨辉三角
    for (int i = 0; i &amp;lt; n; i++) {
        a[i][0] = a[i][i] = 1;
        for (int j = 1; j &amp;lt; i; j++) {
            a[i][j] = a[i-1][j-1] + a[i-1][j];
        }
    }

    for (int i = 0; i &amp;lt; n; i++) {
        for (int j = 0; j &amp;lt;= i; j++) {
            printf(&quot;%10d&quot;, a[i][j]);
        }
        printf(&quot;\n&quot;);
    }
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;在有序数组中插入一个数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int num[n + 1];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;num[i]);
	}
	
	int m;
	scanf(&quot;%d&quot;, &amp;amp;m);
	
	num[n] = m;
	
	for (int i = n - 1; i &amp;gt;= 0; i--) {
		if (num[i] &amp;gt; num[i + 1]) {
			int t = num[i + 1];
			num[i + 1] = num [i];
			num[i] = t;
		}else {
			break;
		}
	}
	
	int mask = 1;
	
	for (int i = 0; i &amp;lt;= n; i++) {
		if (mask == 1) {
			printf(&quot;%d&quot;, num[i]);
			mask = 0;
		}else {
			printf(&quot; %d&quot;, num[i]);
		}
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;筛法求素数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () 
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int Prime[n + 1];
	
	for (int i = 2; i &amp;lt;= n; i++) {
		Prime[i] = 1;
	}
	
	for (int i = 2; i &amp;lt;= n; i++) {
		if (Prime[i] == 1) {
			for (int k = i * i; k &amp;lt;= n; k += i) {
				Prime[k] = 0;
			}
		}
	}

	int mask = 1;
	
	for (int i = 2; i &amp;lt;= n; i++) {
		if (Prime[i] != 0) {
			if (mask == 1) {
				printf(&quot;%d&quot;, i);
				mask = 0;
			}else {
				printf(&quot; %d&quot;, i);
			}
		}
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;最长对称子串&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char s[1001];
	gets(s);
	
	int length_I = 1;
	
	for (int i = 1; s[i] != &apos;\0&apos;; i++) {
		
		int length_i = 1;
		
		for (int j = 1; s[i + j] == s[i - j] &amp;amp;&amp;amp; i - j &amp;gt;= 0; j++) {	
			length_i += 2;
		}
		
		if (length_i &amp;gt; length_I) {
			length_I = length_i;
		}
		
	}
	
	int length_J = 0; 
	
	for (int i = 0; s[i] != &apos;\0&apos;; i++) {
		
		int length_j = 0;
		
		for (int j = 1; s[i + 1 - j] == s[i + j] &amp;amp;&amp;amp; i + 1 - j &amp;gt;= 0; j++) {
			length_j += 2;
		}
		
		if (length_j &amp;gt; length_J) {
			length_J = length_j;
		} 
	}
	
	if (length_J &amp;gt; length_I) {
		printf(&quot;%d&quot;, length_J);
	}else {
		printf(&quot;%d&quot;, length_I);
	}
	
	return 0;
	
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;装睡的人&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    int N;
    scanf(&quot;%d&quot;, &amp;amp;N);
    char name[4]; 
    int breath, pulse;
    
    for (int i = 0; i &amp;lt; N; i++) {
        scanf(&quot;%s %d %d&quot;, name, &amp;amp;breath, &amp;amp;pulse);
        if (breath &amp;lt; 15 || breath &amp;gt; 20 || pulse &amp;lt; 50 || pulse &amp;gt; 70) {
            printf(&quot;%s\n&quot;, name);
        }
    }
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第六章3&lt;/h2&gt;
&lt;h3&gt;个位数统计&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

int main() {
    char N[1005];
    int count[10] = {0};
    
    scanf(&quot;%s&quot;, N);
    
    for (int i = 0; i &amp;lt; strlen(N); i++) {
        int d = N[i] - &apos;0&apos;;
        count[d]++;
    }

    for (int d = 0; d &amp;lt;= 9; d++) {
        if (count[d] &amp;gt; 0) {
            printf(&quot;%d:%d\n&quot;, d, count[d]);
        }
    }
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;找出不是两个数组共有的元素&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void find(int m, int n, int a[m], int b[n], int s[42])
{
	int cnt = 0;
	
	for (int i = 0; i &amp;lt; m; i++) {
		
		int mask = 0;
		for (int j = 0; j &amp;lt; n; j++) {
			if (a[i] == b[j]) {
				mask = 1;
				break;
			}
		}
		if (mask == 0) {
			s[cnt++] = a[i];
		}
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		
		int mask = 0;
		for (int j = 0; j &amp;lt; m; j++) {
			if (b[i] == a[j]) {
				mask = 1;
				break;
			}
		}
		if (mask == 0) {
			s[cnt++] = b[i];
		}
	}
}

void printing (int a[42])
{
	int s[42];
	
	for (int i = 0; i &amp;lt; 42; i++) {
		s[i] = -1;
	}
	
	for (int i = 0; i &amp;lt; 42 &amp;amp;&amp;amp; a[i] != -1; i++) {
		if (s[i] == -1) {
			printf(&quot;%d &quot;, a[i]);
			for (int j = i; j &amp;lt; 42 &amp;amp;&amp;amp; a[j] != -1; j++) {
				if (a[j] == a[i]) {
					s[j] = 0;
				}
			}
		}	
	}	
}

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int a[n];
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;a[i]);
	}
	
	int m;
	scanf(&quot;%d&quot;, &amp;amp;m);
	
	int b[m];
	
	for (int i = 0; i &amp;lt; m; i++) {
		scanf(&quot;%d&quot;, &amp;amp;b[i]);
	}
	
	int s[42];
	
	for (int i = 0; i &amp;lt; 42; i++) {
		s[i] = -1;
	}
	
	find(n, m, a, b, s);
	
	printing(s);
	
	return 0;
	
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;字符串逆序&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

int main ()
{
	char a[81];
	
	fgets(a, sizeof(a), stdin);
	
	int length = strlen(a);
	
	int j = length - 1;
	int i = 0;
	
	while (i &amp;lt; j) {
		char b = a[i];
		a[i] = a[j];
		a[j] = b;
		i++;
		j--;
	}
	
	printf(&quot;%s&quot;, a);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;找鞍点&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    int n;
    scanf(&quot;%d&quot;, &amp;amp;n);
    int a[6][6];
    
    for (int i = 0; i &amp;lt; n; i++) {
        for (int j = 0; j &amp;lt; n; j++) {
            scanf(&quot;%d&quot;, &amp;amp;a[i][j]);
        }
    }
    
    for (int i = 0; i &amp;lt; n; i++) {
        int rowMax = a[i][0];
        for (int j = 1; j &amp;lt; n; j++) {
            if (a[i][j] &amp;gt; rowMax) {
                rowMax = a[i][j];
            }
        }
        
        for (int j = 0; j &amp;lt; n; j++) {
            if (a[i][j] == rowMax) {
                int colMin = a[0][j];
                for (int k = 1; k &amp;lt; n; k++) {
                    if (a[k][j] &amp;lt; colMin) {
                        colMin = a[k][j];
                    }
                }
                if (a[i][j] == colMin) {
                    printf(&quot;%d %d\n&quot;, i, j);
                    return 0;
                }
            }
        }
    }
    
    printf(&quot;NONE\n&quot;);
    return 0;
}


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;求n以内最大的k个素数以及它们的和&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void findPrime (int n, int Prime[])
{	
	for (int i = 2; i &amp;lt;= n; i++) {
		Prime[i] = 1;
	}
	
	for (int i = 2; i * i &amp;lt;= n; i++) {
		if (Prime[i] == 1) {
			for (int k = i * i; k &amp;lt;= n; k += i) {
				Prime[k] = 0;
			}
		}
	}
	
	Prime[0] = 0;
	Prime[1] = 0;
}

int main ()
{
	int max, cnt;
	scanf(&quot;%d %d&quot;, &amp;amp;max, &amp;amp;cnt);
		
	int isPrime[10001];
	findPrime(max, isPrime);
	
	int sum = 0;
	int mask = 0;
	
	for (int i = max; i &amp;gt; 0 &amp;amp;&amp;amp; mask &amp;lt; cnt; i--) {
		if (isPrime[i] == 1) {
			sum += i;
			if (mask == 0) {
				printf(&quot;%d&quot;, i);
			}else {
				printf(&quot;+%d&quot;, i);
			}
			mask++;
		}
	}
	
	printf(&quot;=%d&quot;, sum);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;1234方阵&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void printing (int n, int s[n][n])
{
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; n; j++) {
			printf(&quot;%d&quot;, s[i][j]);
			if (j &amp;lt; n - 1) {
				printf(&quot; &quot;);
			}
		}
		printf(&quot;\n&quot;);
	}
}

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int s[n][n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		s[i][i] = 0;
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		s[n - 1 - i][i] = 0;
	}
	
	int cnt = n - 2;
	int k = cnt;
	int l = cnt;
	int J = 1;
	
	for (int i = 0; k &amp;gt; 0; i++) {
		l = k;
		int j = J;
		while (l &amp;gt; 0) {
			s[i][j] = 1;
			l--;
			j++;
		}
		k -= 2;
		J += 1;
	}
	
	cnt = n - 2;
	k = cnt;
	l = cnt;
	int I = 1;
	
	for (int j = 0; k &amp;gt; 0; j++) {
		l = k;
		int i = I;
		while (l &amp;gt; 0) {
			s[i][j] = 2;
			l--;
			i++;
		}
		k -= 2;
		I += 1;
	}
	
	cnt = n - 2;
	k = cnt;
	l = cnt;
	J = 1;
	
	for (int i = n - 1; k &amp;gt; 0; i--) {
		l = k;
		int j = J;
		while (l &amp;gt; 0) {
			s[i][j] = 3;
			l--;
			j++;
		}
		k -= 2;
		J += 1;
	}
	
	cnt = n - 2;
	k = cnt;
	l = cnt;
	I = 1;
	
	for (int j = n - 1; k &amp;gt; 0; j--) {
		l = k;
		int i = I;
		while (l &amp;gt; 0) {
			s[i][j] = 4;
			l--;
			i++;
		}
		k -= 2;
		I += 1;
	}
	
	printing(n, s);
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;心情查询&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void Traverse1 (int n, int s[n])
{
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;s[i]);
	}
}

void initialize_Traverse2 (int n, int s[n])
{
	for (int i = 0; i &amp;lt; n; i++) {
		s[i] = -1;
	}
	
	int i = 0;
	int j;
	
	while (i &amp;lt; n - 1 &amp;amp;&amp;amp; scanf(&quot;%d&quot;, &amp;amp;j) == 1) {
		if (j &amp;lt; 0 || j &amp;gt; 23) {
			break;
		}else {
			s[i++] = j;
		}
	}
}

int main ()
{
	const int n = 24;
	
	int s[n];
	Traverse1(n, s);

	int hour[n + 1];
	initialize_Traverse2(n + 1, hour);

	int i = 0;
	
	while (i &amp;lt; n + 1 &amp;amp;&amp;amp; hour[i] != -1) {
		
		if (s[hour[i]] &amp;gt; 50) {
			printf(&quot;%d Yes&quot;, s[hour[i]]);
		}else if (s[hour[i]] &amp;lt;= 50) {
			printf(&quot;%d No&quot;, s[hour[i]]);
		}
		
		if (s[hour[i + 1]] != -1) {
			printf(&quot;\n&quot;);
		}else {
			break;
		}
		i++;
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;点赞&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int q[1001] = {0};
	
	for (int i = 0; i &amp;lt; n; i++) {
		int p;
		scanf(&quot;%d&quot;, &amp;amp;p);
		
		for (int j = 0; j &amp;lt; p; j++) {
			int k;
			scanf(&quot;%d&quot;, &amp;amp;k);
			q[k]++;
		}
		
	}
	
	int max = 1000;
	
	for (int i = 1000; i &amp;gt;= 0; i--) {
		if (q[i] &amp;gt; q[max]) {
			max = i;
		}
	}
	
	printf(&quot;%d %d&quot;, max, q[max]);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;古风排版&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int ceiling (double num)
{
	int i = (int)num;
	if (num &amp;gt; i) {
		return i + 1;
	}
	return i;
}


int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	getchar();
	
	char s[1001];
	gets(s);
	
	int len = 0;
	
	while (s[len] != &apos;\0&apos;) {
		len++;
	}
	s[len] = &apos;\0&apos;;
	
	int column = ceiling((double)len / n);
	
	char c[n][column];
	
	int k = 0;
	
	for (int j = column - 1; j &amp;gt;= 0; j--) {
		for (int i = 0; i &amp;lt; n; i++) {
			if (k &amp;lt; len) {
				c[i][j] = s[k++];
			} else {
				c[i][j] = &apos; &apos;;
			}
		}
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		for (int j = 0; j &amp;lt; column; j++) {
			printf(&quot;%c&quot;, c[i][j]);
		}
		printf(&quot;\n&quot;);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;字符串A-B&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	char a[10001];
	gets(a);
	char b[10001];
	gets(b);
	
	int c[10001] = {0};
	
	int k = 0;
	
	for (int i = 0; a[i] != &apos;\0&apos;; i++) {
		for (int j = 0; b[j] != &apos;\0&apos;; j++) {
			if (b[j] == a[i] ) {
				c[k++] = i;
				break;
			}
		}
	}
	
	for (int i = 0; a[i] != &apos;\0&apos;; i++) {
		int mask = 1;
		for (int j = 0; j &amp;lt; k; j++) {
			if (i == c[j]) {
				mask = 0;
				break;
			}
		}
		if (mask == 1) {
			printf(&quot;%c&quot;, a[i]);
		}
	}
	
	return 0;
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;n个数字都不相同的年份&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void initialize_years(int year, int years[4]) 
{
	for (int i = 0; i &amp;lt; 4; i++) {
		years[i] = 0;
	}
	
	int i = 3;
	
	while (year &amp;gt; 0 &amp;amp;&amp;amp; i &amp;gt;= 0) {
		years[i] = year % 10; 
		year /= 10;              
		i--;
	}
}

int main ()
{
	int y;
	scanf(&quot;%d&quot;, &amp;amp;y);

	int s[4];
	
	initialize_years(y, s);
	
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int cnt = 0;
	
	while (1) {
		int mask = 1;
		int num[10] = {0};
		for (int i = 0; i &amp;lt; 4; i++) {
			int j = 0;
			for ( ; j &amp;lt; 10; ) {
				if (s[i] == j) {
					num[j]++;
					break;
				}else {
					j++;
				}
			}	
		}
		for (int k = 0; k &amp;lt; 10; k++) {
			if (n == 4) {
				if (num[k] != 0 &amp;amp;&amp;amp; num[k] != 1) {
					mask = 0;
					break;
				}
			}else if (n == 3) {
				int cnt = 0;
				for (int l = 0; l &amp;lt; 10; l++) {
					if (num[l] == 2) {
						cnt++;
					}
				}
				if (cnt != 1) {
					mask = 0;
					break;
				}
			}else if (n == 2) {
				int tag = 0;
				for (int l = 0; l &amp;lt; 10; l++)
				if (num[l] == 0) {
					tag++;
				}
				if (tag != 8) {
					mask = 0;
					break;
				}
			}
		}
		if (mask == 0) {
			y += 1;
			cnt++;
			initialize_years(y, s);
		}else {
			break;
		}
	}
	
	printf(&quot;%d &quot;, cnt);
	
	for (int i = 0; i &amp;lt; 4; i++) {
		printf(&quot;%d&quot;, s[i]);
	}
	
	return 0;
	
} 

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;矩阵A乘以B&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    int Ra, Ca, Rb, Cb;
    int A[100][100], B[100][100], C[100][100];

    scanf(&quot;%d %d&quot;, &amp;amp;Ra, &amp;amp;Ca);
    for (int i = 0; i &amp;lt; Ra; i++) {
        for (int j = 0; j &amp;lt; Ca; j++) {
            scanf(&quot;%d&quot;, &amp;amp;A[i][j]);
        }
    }

    scanf(&quot;%d %d&quot;, &amp;amp;Rb, &amp;amp;Cb);
    for (int i = 0; i &amp;lt; Rb; i++) {
        for (int j = 0; j &amp;lt; Cb; j++) {
            scanf(&quot;%d&quot;, &amp;amp;B[i][j]);
        }
    }

    if (Ca != Rb) {
        printf(&quot;Error: %d != %d\n&quot;, Ca, Rb);
        return 0;
    }

    for (int i = 0; i &amp;lt; Ra; i++) {
        for (int j = 0; j &amp;lt; Cb; j++) {
            C[i][j] = 0;
            for (int k = 0; k &amp;lt; Ca; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }

    printf(&quot;%d %d\n&quot;, Ra, Cb);
    for (int i = 0; i &amp;lt; Ra; i++) {
        for (int j = 0; j &amp;lt; Cb; j++) {
            if (j &amp;gt; 0) printf(&quot; &quot;);
            printf(&quot;%d&quot;, C[i][j]);
        }
        printf(&quot;\n&quot;);
    }

    return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;查验身份证&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int s[17];
	int a[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
	
	int i = 0;
	int sum = 0;
	
	while (i &amp;lt; 17 &amp;amp;&amp;amp; scanf(&quot;%1d&quot;, &amp;amp;s[i]) == 1) {
		sum += s[i] *a[i];
		i++;
	}
	
	char b;
	scanf(&quot;%c&quot;, &amp;amp;b);
	
	sum %= 11;
	
	int z[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	char m[11] = {&apos;1&apos;, &apos;0&apos;, &apos;X&apos;, &apos;9&apos;, &apos;8&apos;, &apos;7&apos;, &apos;6&apos;, &apos;5&apos;, &apos;4&apos;, &apos;3&apos;, &apos;2&apos;};
	
	char mask = &apos;0&apos;;
	
	for (int i = 0; i &amp;lt; 11; i++) {
		if (sum == z[i]) {
			mask = m[i];
		}
	}
	
	if (mask == b) {
		printf(&quot;No problem&quot;);
	}else {
		printf(&quot;Incorrect&quot;);
	}
	
	return 0;		
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;判断题的评判&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main ()
{
	int n;
	scanf(&quot;%d&quot;, &amp;amp;n);
	
	int AC[n];
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;AC[i]);
	}
	
	int WA[n];
	
	int cnt = 0;
	
	for (int i = 0; i &amp;lt; n; i++) {
		scanf(&quot;%d&quot;, &amp;amp;WA[i]);
		if (WA[i] == AC[i]) {
			cnt++;
		}
	}
	
	double x;
	
	x = 1.0 * cnt / n;
	
	printf(&quot;%.2f%%&quot;, x * 100);
	
	return 0;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;数组元素循环右移问题&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void reverse(int a[], int l, int r) {
	while (l &amp;lt; r) {
		int t = a[l];
		a[l] = a[r];
		a[r] = t;
		l++;
		r--;
	}
}

int main () 
{
	int n, m;
	scanf(&quot;%d %d&quot;, &amp;amp;n, &amp;amp;m);
	m %= n;
	
	int s[n];
	for (int i = n - 1; i &amp;gt;= 0; i--) {
		scanf(&quot;%d&quot;, &amp;amp;s[i]);
	}
	
	reverse(s, 0, m - 1);
	reverse(s, m, n - 1);
	
	for (int i = 0; i &amp;lt; n; i++) {
		printf(&quot;%d &quot;, s[i]);
	}
	
	return 0;
	
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;第七章&lt;/h2&gt;
&lt;h3&gt;定义print函数，输出n个*&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;void print(int k)
{
	for (int i = 1; i &amp;lt;= k; i++)
		printf(&quot;*&quot;);
	printf(&quot;\n&quot;);
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;定义函数求π的近似值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;double funpi(double e)
{
	double flag = 1, sum = 0;
	for (int i = 1;; i++)
	{
		double t = flag / (2 * i - 1);
		if (t &amp;lt; 0)
		{
			if (-t &amp;lt; e)
				break;
		}
		else
		{
			if (t &amp;lt; e)
				break;
		}
		sum += t;  //求和
		flag = -flag;  //正负反转
	}
	return sum;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计函数计算并输出矩形的面积&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;void area(int a, int b)
{
    printf(&quot;%d&quot;, a * b);
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;定义函数prime，判定正整数n是否素数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;math.h&amp;gt;
int prime(int n)
{
	for (int i = 2; i &amp;lt;= sqrt(n); i++)
		if (n % i == 0)
			return 0;

	return 1;
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计函数实现冒泡排序&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;void sort(int a[], int n)
{
	for (int i = 0; i &amp;lt; n - 1; i++)  //一趟冒泡排序,把最小的数字放在最末尾
	{
		for (int j = 0; j &amp;lt; n - i - 1; j++)  //每经过一趟冒泡排序,需要检索的数字个数-1
		{
			if (a[j] &amp;lt; a[j + 1])  //如果左边的数字小于右边的数字,实现相邻两个数的交换
			{
				int t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}
		}
	}
}

void print(int a[], int n)
{
	for (int i = 0; i &amp;lt; n; i++)
	{
		if (i == 0)
			printf(&quot;%d&quot;, a[i]);
		else
			printf(&quot; %d&quot;, a[i]);
	}
	printf(&quot;\n&quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计函数实现矩阵的转置&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;void convert(int arr1[][10], int arr2[][10], int x, int y)
{
	for (int i = 0; i &amp;lt; x; i++)
		for (int j = 0; j &amp;lt; y; j++)
			arr2[j][i] = arr1[i][j];  // 矩阵行列坐标互换
}

void print(int arr[][10], int x, int y)  //二维数组的行可以不初始化,列一定要初始化
{
	for (int i = 0; i &amp;lt; x; i++)  //控制行数
	{
		for (int j = 0; j &amp;lt; y; j++)  //控制列数
		{
			if (j == 0)
				printf(&quot;%d&quot;, arr[i][j]);
			else
				printf(&quot; %d&quot;, arr[i][j]);
		}
		printf(&quot;\n&quot;);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计函数实现二分查找&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;int BinSearch(int a[], int n, int x)
{
	int left = 0;  //数组最左侧元素下标
	int right = n - 1;  //数组最右侧元素下标
	while (left &amp;lt;= right)
	{
		//int mid = (right + left) / 2;
		int mid = left + (right - left) / 2;  //防止数据过大，越界
		if (x &amp;lt; a[mid])
			left = mid + 1;
		else if (x &amp;gt; a[mid])
			right = mid - 1;
		else
			return mid;
	}
	return -1;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;定义menu函数，输出菜单选项&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;void Menu()
{
	printf(&quot;       Menu\n&quot;);
	printf(&quot;  (1)--读取数据\n&quot;);
	printf(&quot;  (2)--数据计算\n&quot;);
	printf(&quot;  (3)--查找数据\n&quot;);
	printf(&quot;  (4)--输出数据\n&quot;);
	printf(&quot;  (0)--退出程序\n&quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计函数计算学生的平均成绩&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;double average(int a[], int n)
{
	double sum = 0;
	for (int i = 0; i &amp;lt; n; i++)
		sum = sum += a[i];
	return  sum / n;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计递归函数模拟汉诺塔游戏&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;void move(int n, char a, char b, char c)
{
	if (n == 1)
		printf(&quot;%c--&amp;gt;%c\n&quot;, a, c);  //当只有一个盘子时,直接从起始柱移到目标柱
	else
	{
		move(n - 1, a, c, b);  //第一步:将n-1个盘子由a移动到b,注意此时起始柱是a,中转柱是c,目标柱是b; 
		printf(&quot;%c--&amp;gt;%c\n&quot;, a, c);  //第二步:将第n个盘子从起始柱移到目标柱
		move(n - 1, b, a, c);  //第三步:将n-1个盘子由b移动到c,注意此时起始柱是b,中转柱是a,目标柱是c; 
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计递归函数计算Fibonacci数列的第n项&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;int fib(int n)
{
	if (n &amp;lt;= 1)
		return 1;
	else
		return fib(n - 1) + fib(n - 2);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计递归函数计算组合&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;int fun(int m, int n)
{
	if (n == 0 || n == m)  //c(0,m)和c(m,m)都为1(特判)
		return 1;
	else
		return fun(m - 1, n - 1) + fun(m - 1, n);  //组合数公式 c(n,m)=c(n-1,m-1)+c(n-1,m)  m&amp;gt;=n
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计递归函数计算两个整数的最大公约数&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;int gcd(int m, int n)  //辗转相除法
{
    if (n == 0)
        return m;
    else
        return gcd(n, m % n);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计递归函数计算n！&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;int fac(int n)
{
	if (n &amp;lt;= 1)
		return 1;
	else
		return n * fac(n - 1);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;设计max函数，计算三个整数的最大值&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;int max(int a, int b, int c)
{
	if (a &amp;gt;= b &amp;amp;&amp;amp; a &amp;gt;= c)
		return a;
	if (b &amp;gt;= a &amp;amp;&amp;amp; b &amp;gt;= c)
		return b;
	if (c &amp;gt;= a &amp;amp;&amp;amp; c &amp;gt;= b)
		return c;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>2025武汉新生赛部分题解及游记</title><link>https://blog.everlasting.xin/posts/2025-wuhan-freshman-league/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/2025-wuhan-freshman-league/</guid><description>记录我参加 2025 武汉新生赛的经历，以及部分题目的题解和代码。</description><pubDate>Mon, 22 Dec 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;2025武汉新生赛部分题解及游记&lt;/h1&gt;
&lt;h2&gt;游记&lt;/h2&gt;
&lt;p&gt;2025 年已经见底，今年最后一场参加的线下赛也告一段落。不知不觉已经过了快半年的时间，在这里先感谢这半年来帮助过我的学长，同学们，感谢他们作为我的领路人，帮助我应对大学里的事物，带我入门算法，学习计算机相关的知识。希望未来的自己能够争气点。&lt;/p&gt;
&lt;p&gt;&amp;lt;!-- more --&amp;gt;&lt;/p&gt;
&lt;p&gt;本次比赛仍需要反思的，首先是保持冷静。A 题样例都没看就开始搓，最后发现时几乎是全部重写，浪费了大量时间。另外对于一些细节方面仍需注意。例如算式中存在的计算符的优先性。最后对于拿不太准的代码，应当多造样例多测，这样能避免很多不应该出现的罚时。&lt;/p&gt;
&lt;p&gt;这次是第二次去华农参加的比赛。相对于第一次，这次抽到了怎么按也按不动的键盘，刚交完 Wrong Answer 后就蓝屏的电脑，运气还是差了点 TAT。但这次发的面包好吃(&lt;s&gt;虽然不咋饿&lt;/s&gt;)。这次仍然很幸运的拿到了签到题的一血，让我也不至于空手而归。另外，华农不愧是华“农”，比赛完在华农乱逛，田，一望无际的田~~&lt;/p&gt;
&lt;p&gt;经历了这次比赛，意识到了自己与强者之间的差距真的很大。。。在算法这条路上仍是任重道远。希望自己以后加油吧！&lt;/p&gt;
&lt;h2&gt;部分题解&lt;/h2&gt;
&lt;h3&gt;L - 那我问你&lt;/h3&gt;
&lt;h4&gt;题意：&lt;/h4&gt;
&lt;p&gt;输入三个整数 a，b，c，输出“The paper you submitted have a Pros and b Cons, so I have c Questions for you.”。&lt;/p&gt;
&lt;h4&gt;代码：&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 1e9 + 7;

void solve ()
{
    ll a, b, c; cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b &amp;gt;&amp;gt; c;
    cout &amp;lt;&amp;lt; &quot;The paper you submitted have &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; Pros and &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; &quot; Cons, so I have &quot; &amp;lt;&amp;lt; c &amp;lt;&amp;lt; &quot; Questions for you.&quot;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;A - 昨日重现&lt;/h3&gt;
&lt;h4&gt;题意：&lt;/h4&gt;
&lt;p&gt;给定一个长度不超过 100 的字符串，在五所大学(HUST, WHU, WHUT, HZAU, CCNU)的缩写中，找出在字符串中作为子序列出现次数最多且字典序最小的一个，输出大学的缩写及最大次数。&lt;/p&gt;
&lt;h4&gt;思路：&lt;/h4&gt;
&lt;p&gt;这里就不深究此题了，for 循环足以解决。&lt;/p&gt;
&lt;h4&gt;代码：&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 1e9 + 7;

void solve ()
{
    string s; cin &amp;gt;&amp;gt; s;
    vector &amp;lt;ll&amp;gt; cnt(5, 0);
    ll n = s.size();

    for (ll i = 0; i &amp;lt; n; i++) {
        if (s[i] == &apos;C&apos;) {
            for (ll j = i + 1; j &amp;lt; n; j++) {
                if (s[j] == &apos;C&apos;) {
                    for (ll k = j + 1; k &amp;lt; n; k++) {
                        if (s[k] == &apos;N&apos;) {
                            for (ll l = k + 1; l &amp;lt; n; l++) {
                                if (s[l] == &apos;U&apos;) cnt[0]++;
                            }
                        }
                    }
                }
            }
        }
    }

    for (ll i = 0; i &amp;lt; n; i++) {
        if (s[i] == &apos;H&apos;) {
            for (ll j = i + 1; j &amp;lt; n; j++) {
                if (s[j] == &apos;U&apos;) {
                    for (ll k = j + 1; k &amp;lt; n; k++) {
                        if (s[k] == &apos;S&apos;) {
                            for (ll l = k + 1; l &amp;lt; n; l++) {
                                if (s[l] == &apos;T&apos;) cnt[1]++;
                            }
                        }
                    }
                }
            }
        }
    }

    for (ll i = 0; i &amp;lt; n; i++) {
        if (s[i] == &apos;H&apos;) {
            for (ll j = i + 1; j &amp;lt; n; j++) {
                if (s[j] == &apos;Z&apos;) {
                    for (ll k = j + 1; k &amp;lt; n; k++) {
                        if (s[k] == &apos;A&apos;) {
                            for (ll l = k + 1; l &amp;lt; n; l++) {
                                if (s[l] == &apos;U&apos;) cnt[2]++;
                            }
                        }
                    }
                }
            }
        }
    }

    for (ll i = 0; i &amp;lt; n; i++) {
        if (s[i] == &apos;W&apos;) {
            for (ll j = i + 1; j &amp;lt; n; j++) {
                if (s[j] == &apos;H&apos;) {
                    for (ll k = j + 1; k &amp;lt; n; k++) {
                        if (s[k] == &apos;U&apos;) {
                            for (ll l = k + 1; l &amp;lt; n; l++) {
                                if (s[l] == &apos;T&apos;) cnt[4]++;
                            }
                        }
                    }
                }
            }
        }
    }

    for (ll i = 0; i &amp;lt; n; i++) {
        if (s[i] == &apos;W&apos;) {
            for (ll j = i + 1; j &amp;lt; n; j++) {
                if (s[j] == &apos;H&apos;) {
                    for (ll k = j + 1; k &amp;lt; n; k++) {
                        if (s[k] == &apos;U&apos;) cnt[3]++;
                    }
                }
            }
        }
    }

    if (cnt[0] == max({cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]})) {
        cout &amp;lt;&amp;lt; &quot;CCNU &quot; &amp;lt;&amp;lt; cnt[0] &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (cnt[1] == max({cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]})) {
        if (cnt[0] == cnt[1]) {
            cout &amp;lt;&amp;lt; &quot;CCNU &quot; &amp;lt;&amp;lt; cnt[0] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;HUST &quot; &amp;lt;&amp;lt; cnt[1] &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }else if (cnt[2] == max({cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]})) {
        if (cnt[0] == cnt[2]) {
            cout &amp;lt;&amp;lt; &quot;CCNU &quot; &amp;lt;&amp;lt; cnt[0] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (cnt[1] == cnt[2]) {
            cout &amp;lt;&amp;lt; &quot;HUST &quot; &amp;lt;&amp;lt; cnt[1] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;HZAU &quot; &amp;lt;&amp;lt; cnt[2] &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }else if (cnt[3] == max({cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]})) {
        if (cnt[0] == cnt[3]) {
            cout &amp;lt;&amp;lt; &quot;CCNU &quot; &amp;lt;&amp;lt; cnt[0] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (cnt[1] == cnt[3]) {
            cout &amp;lt;&amp;lt; &quot;HUST &quot; &amp;lt;&amp;lt; cnt[1] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (cnt[2] == cnt[3]) {
            cout &amp;lt;&amp;lt; &quot;HZAU &quot; &amp;lt;&amp;lt; cnt[2] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;WHU &quot; &amp;lt;&amp;lt; cnt[3] &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }else if (cnt[4] == max({cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]})) {
        if (cnt[0] == cnt[4]) {
            cout &amp;lt;&amp;lt; &quot;CCNU &quot; &amp;lt;&amp;lt; cnt[0] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (cnt[1] == cnt[4]) {
            cout &amp;lt;&amp;lt; &quot;HUST &quot; &amp;lt;&amp;lt; cnt[1] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (cnt[2] == cnt[4]) {
            cout &amp;lt;&amp;lt; &quot;HZAU &quot; &amp;lt;&amp;lt; cnt[2] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else if (cnt[3] == cnt[4]) {
            cout &amp;lt;&amp;lt; &quot;WHU &quot; &amp;lt;&amp;lt; cnt[3] &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;WHUT &quot; &amp;lt;&amp;lt; cnt[4] &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;B - 易守难攻&lt;/h3&gt;
&lt;h4&gt;题意：&lt;/h4&gt;
&lt;p&gt;给定一个空的 n 行 m 列的网格，需要往每一个格子填入一个$1$ ~ $n\times m$的高度值，满足有 k 个网格的高度值严格大于 8 个相邻格子的高度值，且这 k 个网格不位于边界上。输出满足条件的网格，或者报告不存在这样的分配方式。&lt;/p&gt;
&lt;h4&gt;思路：&lt;/h4&gt;
&lt;p&gt;首先明确：将大数一个隔一个的放是最大化能放置网格的放置方法。手模几个样例可以发现，若$(n - 1) / 2 \times (m - 1) / 2 &amp;lt; k$，则放不下满足条件的 k 个网格。我们可以从最大数开始放置。先将大数一个隔一个数地放，保证大数之间不会互相干扰。再依次放置其他数即可，可以保证大数总是可以满足条件的，且其他数不会形成新的满足条件的网格。&lt;/p&gt;
&lt;h4&gt;代码：&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 1e9 + 7;

void solve ()
{
    ll n, m, k; cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m &amp;gt;&amp;gt; k;
    if (((n - 1) / 2) * ((m - 1) / 2) &amp;lt; k) {
        cout &amp;lt;&amp;lt; &quot;No&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        return;
    }

    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; v(n + 1, vector &amp;lt;ll&amp;gt; (m + 1));
    vector &amp;lt;vector &amp;lt;bool&amp;gt; &amp;gt; vis(n + 1, vector &amp;lt;bool&amp;gt; (m + 1, false));

    ll t = n * m;
    if (k != 0) {
        ll cnt = 0;
        bool found = true;
        for (int i = 2; i &amp;lt; n; i += 2) {
            for (int j = 2; j &amp;lt; m; j += 2) {
                cnt++;
                v[i][j] = t--;
                vis[i][j] = true;
                if (cnt == k) found = false;
                if (!found) break;
            }
            if (!found) break;
        }
    }

    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            if (vis[i][j]) continue;
            v[i][j] = t--;
        }
    }

    cout &amp;lt;&amp;lt; &quot;Yes&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            cout &amp;lt;&amp;lt; v[i][j] &amp;lt;&amp;lt; &apos; &apos;;
        }
        cout &amp;lt;&amp;lt; &apos;\n&apos;;
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;F - Anon 的疑问&lt;/h3&gt;
&lt;h4&gt;题意：&lt;/h4&gt;
&lt;p&gt;询问$q$次$(1 \leq q \leq 1e6)$，每次询问给定一个正整数$n(1 \leq n \leq 2e7)$，判断其能否被分解为两个正整数的平方和。&lt;/p&gt;
&lt;h4&gt;思路：&lt;/h4&gt;
&lt;p&gt;这里给出两种思路。&lt;/p&gt;
&lt;p&gt;第一种思路：首先可以观察到这里的数据量并不是很大，我们完全可以直接预处理平方在$2e7$内的数，然后枚举得到所有满足条件的正整数。
时间复杂度:$O(2e7)$。&lt;/p&gt;
&lt;p&gt;第二种思路：可以利用两平方和定理：对于任意的正整数$n = a^2 + b^2(a, b \in Z)$，当且仅当在 n 的质因数分解中，所有形如$p \equiv 3 (mod 4)$的质数，其指数都是偶数。根据定理，我们可以先预处理出在$2e7$内所有数的最小质因数，然后再根据每个数判断其指数奇偶性。&lt;/p&gt;
&lt;p&gt;但是这里由于询问次数可能很多，时间复杂度相对于暴力可能没有优势，且无法通过本题，仅供参考。&lt;/p&gt;
&lt;p&gt;时间复杂度：$O(q\times nlogn)$。&lt;/p&gt;
&lt;h4&gt;代码：&lt;/h4&gt;
&lt;h5&gt;思路一：&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 1e9 + 7;

bool vis[20000005];//这里如果用vector记录可能会被卡常

void solve ()
{
    ll n; cin &amp;gt;&amp;gt; n;
    if (vis[n]) {
        cout &amp;lt;&amp;lt; &quot;Yes&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else {
        cout &amp;lt;&amp;lt; &quot;No&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int _ = 1;
    cin &amp;gt;&amp;gt; _;

    for (int i = 1; i &amp;lt; 4473; i++) {
        if (i * i &amp;gt; 2e7 + 2) break;
        for (int j = i; j &amp;lt; 4473; j++) {
            if (i * i + j * j &amp;gt; 2e7 + 2) break;
            vis[i * i + j * j] = true;
        }
    }

    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h5&gt;思路二：（仅供参考）&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int N = 2e7 + 1;
const double eps = 1e-5;
const ll mod = 1e9 + 7;

bool isprime[N];
int prime[N], mnp[N];
ll cnt = 0;

void get_mn_prime_factor ()
{
    mnp[1] = 1;
    for (int i = 2; i &amp;lt; N; i++) {
        if (!isprime[i]) {
            prime[cnt++] = i;
            mnp[i] = i;
        }
        for (int j = 0; j &amp;lt; cnt &amp;amp;&amp;amp; i * prime[j] &amp;lt; N; j++) {
            isprime[i * prime[j]] = true;
            mnp[i * prime[j]] = prime[j];
            if (i % prime[j] == 0) break;
        }
    }
}

void solve ()
{
    ll n; cin &amp;gt;&amp;gt; n;

    auto check = [&amp;amp;] (int x) -&amp;gt; bool {
        ll t = x;
        while (t != 1) {
            ll p = mnp[t];
            ll cnt = 0;
            while (t % p == 0) {
                t /= p;
                cnt++;
            }
            if (p % 4 == 3 &amp;amp;&amp;amp; cnt &amp;amp; 1) {
                return false;
            }
        }
        if ((ll)sqrtl(x) * (ll)sqrtl(x) == x) return false;//特判
        else return true;
    };

    cout &amp;lt;&amp;lt; (check(n) ? &quot;Yes&quot; : &quot;No&quot;) &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    cin &amp;gt;&amp;gt; _;
    get_mn_prime_factor();
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;G - 你好，世界&lt;/h3&gt;
&lt;h4&gt;题意：&lt;/h4&gt;
&lt;p&gt;有一个初始值为 0 的 N 位计数器，用来预测一条指令是否应当执行。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;当扫描到一条指令时，若计数器的值小于$2^{N - 1}$，则预测该指令将不被执行，否则预测将被执行。&lt;/li&gt;
&lt;li&gt;无论是否预测正确，如果当前指令的真实状况为需要执行，则计数器增加 1，否则计数器减少 1。&lt;/li&gt;
&lt;li&gt;计数器的增加和减少不会超过$[0,2^N)$这一界限。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;你需要构造一个长度为 len 的 01 字符串（指令），0 代表不执行，1 代表执行，使得预测错误的次数最大。&lt;/p&gt;
&lt;h4&gt;思路：&lt;/h4&gt;
&lt;p&gt;诈骗题。理解题意后，不难发现只需要使前$2^{N - 1}$个指令执行，后面的指令只需不执行，执行(01 循环)即可。&lt;/p&gt;
&lt;h4&gt;代码：&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 1e9 + 7;

ll qpow (ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b &amp;amp; 1) res = res * a;
        a = a * a;
        b &amp;gt;&amp;gt;= 1;
    }
    return res;
}

void solve ()
{
    ll n, len; cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; len;
    ll tag = len;
    if (n &amp;lt;= 60) tag = min(qpow(2, n - 1), len);

    for (int i = 0; i &amp;lt; tag; i++) {
        cout &amp;lt;&amp;lt; 1;
    }
    for (int i = 0; i &amp;lt; len - tag; i++) {
        cout &amp;lt;&amp;lt; (i &amp;amp; 1);
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;H - 哆啦 A 梦的神奇铜锣烧储存系统&lt;/h3&gt;
&lt;h4&gt;题意：&lt;/h4&gt;
&lt;p&gt;有$n$个宝箱，其中有$k$个宝箱里装有铜锣烧，哆啦 A 梦先从中选择$m$个他认为最有可能装有铜锣烧的宝箱，然后在剩下的$n - m$个宝箱中随机打开$n - (m + q)$个空箱子（若没有空箱子则不打开），最后剩下$q$个宝箱是关闭的。
求出剩下的未打开$q$个宝箱中铜锣烧的期望数量（模 998244353）。&lt;/p&gt;
&lt;h4&gt;思路：&lt;/h4&gt;
&lt;p&gt;简洁的思路是：我们考虑任意一个真箱子，在每一次选完$m$个后，这个箱子仍然存在于$n - m$个箱子的期望为$E[X_i] = \frac{n - m}{n}$。一共有$k$个真箱子，只需要将$k$个期望累加就能得出答案：$\frac{n - m}{n} \times k$。&lt;/p&gt;
&lt;p&gt;&amp;lt;br&amp;gt;
详细过程：（鸣谢笔者ichooooooo！）&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;首先，这是一道超几何分布题&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;经典场景：总共有$N$个商品，其中$M$个特殊品，选取$n$个出来&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;求$n$个商品中特殊商品期望
设$X$是$n$个商品里的特殊品数量 $E = \sum_{X = 0}^{M}(X \times P(X))$&lt;/p&gt;
&lt;p&gt;这里$P(X)$是从$n$个中抽取$X$个特殊品的概率， $X \times P(X)$ 是抽到$i$个特殊元素时，特殊品数量的期望贡献，$(n - X) \times P(X)$ 则是抽到$i$个特殊元素时，非特殊品数量的期望贡献&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;求$P(X)$
超几何分布知识，我们用$\binom{k}{i}$表示$C(i, k)$，最终公式
$$\frac{\binom{M}{X}\binom{N - M}{n - X}}{\binom{N}{n}}$$
其中$\binom{M}{X}$表示从$X$个总特殊品选取$M$个，那么剩下$n - X$个是非特殊，再从$N - M$个总非特殊选取$n - X$个，相乘是“有利情况”，除总情况就是概率&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;期望化简后求和结果
$$\frac{M}{N} \times n$$&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;回到题目，根据上面我们最终需要得到&lt;strong&gt;抽 n 个商品时，非特殊商品的期望&lt;/strong&gt;，即
$${\sum_{i = 0}^{min(k, m)}(k - i)} \times P(i)$$
展开得
$$\frac{\sum_{i = 0}^{min(k, m)}\binom{k}{i}\binom{n - k}{m - i}(k - i)}{\binom{n}{m}}$$
化简得
$$\frac{n - m}{n} \times k$$&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;关于为什么 q 不会影响到最终结果&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;q 只抽取空箱子，不影响特殊品的数量，根据公式，P(i)不变，权值 k - i 也不变，所以结果不变&lt;/p&gt;
&lt;h4&gt;代码：&lt;/h4&gt;
&lt;h5&gt;原始公式:&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 1e6 + 10;
const double eps = 1e-5;
const ll mod = 998244353;

vector &amp;lt;ll&amp;gt; f(MAXN), g(MAXN);

ll qpow (ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b &amp;amp; 1) res = res * a % mod;
        a = a * a % mod;
        b &amp;gt;&amp;gt;= 1;
    }
    return res % mod;
}

ll C (ll n, ll m)
{
    if (m &amp;lt; 0 || m &amp;gt; n) return 0;
    return f[n] * g[m] % mod * g[n - m] % mod;
}

void solve ()
{
    ll n, k, m, q; cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k &amp;gt;&amp;gt; m &amp;gt;&amp;gt; q;
    ll a = 0, b = 0;
    for (int i = 0; i &amp;lt;= min(k, m); i++) {
        a = (a + C(k, i) * C(n - k, m - i) % mod * (k - i) % mod) % mod;
    }
    b = C(n, m);
    ll ans = a * qpow(b, mod - 2) % mod;
    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;

    f[0] = 1, g[0] = 1;
    for (int i = 1; i &amp;lt; MAXN; i++) {
        f[i] = f[i - 1] * i % mod;
        g[i] = qpow(f[i], mod - 2) % mod;
    }

    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h5&gt;化简：&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 998244353;

ll qpow (ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b &amp;amp; 1) res = res * a % mod;
        a = a * a % mod;
        b &amp;gt;&amp;gt;= 1;
    }
    return res % mod;
}

void solve ()
{
    ll n, k, m, q; cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k &amp;gt;&amp;gt; m &amp;gt;&amp;gt; q;
    cout &amp;lt;&amp;lt; (n - m) * k % mod * qpow(n, mod - 2) % mod &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>2025菜鸟杯部分题解</title><link>https://blog.everlasting.xin/posts/2025_wust_cnb/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/2025_wust_cnb/</guid><description>整理 2025 菜鸟杯部分题目的题解与代码实现。</description><pubDate>Mon, 15 Dec 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;2025菜鸟杯部分题解&lt;/h1&gt;
&lt;h2&gt;A - hello&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;第一行输出“HELL0 WUSTACM!”，第二行输出“maintain integrity,think diligently, and challenge yourself”。&lt;/p&gt;
&lt;p&gt;&amp;lt;!-- more --&amp;gt;&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
    cout &amp;lt;&amp;lt; &quot;HELL0 WUSTACM!&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    cout &amp;lt;&amp;lt; &quot;maintain integrity,think diligently, and challenge yourself&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;C - 杨弟的电梯&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;输入一个整数 n 和 0 或 1，0 代表夏天，1 代表冬天。
夏天时人数不少于 10 人输出 hot，不到 10 人输出 cool。
冬天时人数不少于 10 人输出 warm，不到 10 人输出 cold。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n, a;

void solve ()
{
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; a;
    if (n &amp;gt; 15) {
        cout &amp;lt;&amp;lt; &quot;error&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        return;
    }
    if (a == 0) {
        if (n &amp;lt; 10) {
            cout &amp;lt;&amp;lt; &quot;cool&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;hot&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }else {
        if (n &amp;lt; 10) {
            cout &amp;lt;&amp;lt; &quot;cold&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        }else {
            cout &amp;lt;&amp;lt; &quot;warm&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        }
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;F - 猫猫&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;根据程序输出，程序如下：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;miao_func(x):
    miaomiao (x &amp;lt; 1)
        miaomiaomiaowu 0
    miaomiaomiao (x &amp;amp; 1)
        miaomiaomiaowu x + miao_func(x - 2)
    miaomiaomioa
        miaomiaomiaowu miao_func(x - 2) - x
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;喵语：
miaomiao : if
miaomiaomiao : else if
miaomiaomioa : else
miaomiaomiaowu : return&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
    cin &amp;gt;&amp;gt; n;

    auto func = [&amp;amp;] (ll x, auto self) -&amp;gt; ll {
        if (x &amp;lt; 1) {
            return 0;
        }else if (x &amp;amp; 1) {
            return x + self(x - 2, self);
        }else {
            return self(x - 2, self) - x;
        }
    };

    ll ans = func(n, func);

    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;D - 装糖果&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定 n 种类型的糖果，k 和每种类型糖果的数量，求至少买多少个袋子能满足以下限制条件：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;每个袋子最多能装下 k 个糖果&lt;/li&gt;
&lt;li&gt;每个袋子中同一种类的糖果至多只能有一个&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;贪心。考虑最后的袋子有两种可能，一种是包含多种糖果，一种是只有一种糖果。对于第一种情况，至少的袋子数量即为 ceil(sum / k),对于第二种情况，至少的袋子数量即为最大的糖果数量。两种情况取最大值即可。
时间复杂度：O(n)。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n, k;

void solve ()
{
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k;
    vector &amp;lt;ll&amp;gt; v(n + 1);
    ll mx = 0;
    ll sum = 0;
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; v[i];
        sum += v[i];
        mx = max(mx, v[i]);
    }

    ll t;
    if (sum % k == 0) {
        t = sum / k;
    }else {
        t = sum / k + 1;
    }

    cout &amp;lt;&amp;lt; max(t, mx);
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;G - 礼包和 scandi&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定碗的数量和每个碗中的米饭量。scandi 要吃完所有米饭且想要米饭量尽量少，礼包想要 scandi 吃的米饭量尽量多。在开始吃饭前，两人可以轮流对米饭量进行调整，礼包先手，过程如下：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;任选一个满足 a&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; != a&amp;lt;sub&amp;gt;i+1&amp;lt;/sub&amp;gt;的 i。&lt;/li&gt;
&lt;li&gt;将 a&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;变为 func(a&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;，a&amp;lt;sub&amp;gt;i+1&amp;lt;/sub&amp;gt;)。&lt;/li&gt;
&lt;li&gt;当无法找到满足要求的 i 时，调整环节结束。
注意：对于 scandi 而言，func() = min()，对于礼包而言，func() = max()。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;求最终 scandi 需要吃掉的米饭总量&lt;/p&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;诈骗题。手模样例后发现，当所有数等于最后一个数时才不会满足题意。直接输出即可。
时间复杂度：O(n)。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
    cin &amp;gt;&amp;gt; n;
    vector &amp;lt;ll&amp;gt; v(n + 1, 0);
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; v[i];
    }

    cout &amp;lt;&amp;lt; v[n] * n &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;H - 凡安要当超级农民&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定矩阵的长和宽为 n 和 m，并给定次数 q。接下来的 q 行中，给定魔法生效点座标，延伸长度和魔法效果。
魔法效果：在生效点上，上下左右依次延伸 k 个点，使得每个点的产量增加 s(初始产量为 0)。
求最终矩阵中每个点的产量。&lt;/p&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;数据量不大，模拟即可。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n, m, q;

void solve ()
{
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m &amp;gt;&amp;gt; q;
    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; v(n + 1, vector &amp;lt;ll&amp;gt; (m + 1, 0));

    while (q--) {
        ll x, y, k, s;
        cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; y &amp;gt;&amp;gt; k &amp;gt;&amp;gt; s;
        v[x][y] += s;
        for (int i = x - k; i &amp;lt;= x + k; i++) {
            if (i == x) continue;
            ll xx = (i + n - 1) % n + 1;
            v[xx][y] += s;
        }
        for (int i = y - k; i &amp;lt;= y + k; i++) {
            if (i == y) continue;
            ll yy = (i + m - 1) % m + 1;
            v[x][yy] += s;
        }
    }

    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            cout &amp;lt;&amp;lt; v[i][j] &amp;lt;&amp;lt; &apos; &apos;;
        }
        cout &amp;lt;&amp;lt; &apos;\n&apos;;
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;L - 逃课计划&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;一周七天，每天有六节课，给定老师的具体查课时间，即第几天第几节。在两天不能逃同一节课的情况下，求出可能的逃课计划数量。&lt;/p&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;最大可能不超过 3e5 种情况，因此直接暴力 dfs 即可。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; e(8);
ll n;
ll ans = 0;

void solve ()
{
    cin &amp;gt;&amp;gt; n;
    map &amp;lt;pair&amp;lt;ll, ll&amp;gt;, bool&amp;gt; mp;
    for (int i = 0; i &amp;lt; n; i++) {
        int a, b;
        cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b;
        mp[{a, b}] = true;
    }

    for (int i = 1; i &amp;lt;= 7; i++) {
        for (int j = 1; j &amp;lt;= 6; j++) {
            if (!mp[{i, j}]) {
                e[i].push_back(j);
            }
        }
    }

    auto dfs = [&amp;amp;] (ll day, ll course, auto self) -&amp;gt; void {
        if (day == 7) {
            ans++;
            return;
        }

        for (auto x : e[day + 1]) {
            if (x == course) continue;
            self(day + 1, x, self);
        }
    };

    for (auto x : e[1]) {
        dfs(1, x, dfs);
    }

    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;E - 比较 A 和 B 的大小&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定一种新的比较两数大小的方式：整数部分相同，但小数部分按整数来比较大小。例如：0.13 &amp;gt; 0.3, 0.50 &amp;gt; 0.5。
给定两个数，若新的方式与数学方式的比大小结果相同，输出&quot;ni shi dui de&quot;
否则，输出&quot;ni cuo le, ying gai shi ‘正确答案’&quot;。 “正确答案”为：&amp;lt;, &amp;gt;, =。&lt;/p&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;首先注意到若存在一个数是整数，两种比大小的结果一定相同。接下来先判断整数部分，若整数部分不同，比大小结果一定也相同。若相同再来比较小数部分。
小数部分中，分别将其根据数学方法和新的方式比较（注意前导 0 和后导 0 的讨论），查看两者结果是否不同即可。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 998244353;

string a1, a2;

void solve ()
{
    cin &amp;gt;&amp;gt; a1 &amp;gt;&amp;gt; a2;
    if (a1.find(&apos;.&apos;) == string::npos || a2.find(&apos;.&apos;) == string::npos) {
        cout &amp;lt;&amp;lt; &quot;ni shi dui de&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        return;
    }
    string s1 = a1.substr(0, a1.find(&apos;.&apos;));
    string s2 = a2.substr(0, a2.find(&apos;.&apos;));

    if (s1 != s2) {
        cout &amp;lt;&amp;lt; &quot;ni shi dui de&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
        return;
    }

    string ss1 = a1.substr(a1.find(&apos;.&apos;) + 1);
    string ss2 = a2.substr(a2.find(&apos;.&apos;) + 1);

    int found2 = 0;//normal compare
    for (int i = 0; i &amp;lt; min(ss1.size(), ss2.size()); i++) {
        if (ss1[i] &amp;lt; ss2[i]) {
            found2 = 1;
            break;
        }else if (ss1[i] &amp;gt; ss2[i]) {
            found2 = 2;
            break;
        }
    }

    if (found2 == 0) {
        if (ss1.size() &amp;lt; ss2.size()) {
            bool foundd = false;
            for (int i = ss1.size(); i &amp;lt; ss2.size(); i++) {
                if (ss2[i] != &apos;0&apos;) {
                    foundd = true;
                }
            }
            if (foundd) {
                found2 = 1;
            }
        }else if (ss1.size() &amp;gt; ss2.size()) {
            bool foundd = false;
            for (int i = ss2.size(); i &amp;lt; ss1.size(); i++) {
                if (ss1[i] != &apos;0&apos;) {
                    foundd = true;
                }
            }
            if (foundd) {
                found2 = 2;
            }
        }
    }

    int found3 = 0;//require compare
    string t1; int index = 0;//remove 0 from front
    while (index &amp;lt; ss1.size()) {
        if (ss1[index] != &apos;0&apos;) {
            break;
        }
        index++;
    }
    t1 = ss1.substr(index, ss1.size() - index);

    string t2; index = 0;
    while (index &amp;lt; ss2.size()) {
        if (ss2[index] != &apos;0&apos;) {
            break;
        }
        index++;
    }
    t2 = ss2.substr(index, ss2.size() - index);

    if (t1.size() &amp;lt; t2.size()) {
        found3 = 1;
    }else if (t1.size() &amp;gt; t2.size()) {
        found3 = 2;
    }else {
        for (int i = 0; i &amp;lt; t1.size(); i++) {
            if (t1[i] &amp;lt; t2[i]) {
                found3 = 1;
                break;
            }else if (t1[i] &amp;gt; t2[i]) {
                found3 = 2;
                break;
            }
        }
    }

    if (found2 == found3) {
        cout &amp;lt;&amp;lt; &quot;ni shi dui de&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (found2 == 0 &amp;amp;&amp;amp; found3 == 1) {
        cout &amp;lt;&amp;lt; &quot;ni cuo le, ying gai shi &amp;lt;&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (found2 == 0 &amp;amp;&amp;amp; found3 == 2) {
        cout &amp;lt;&amp;lt; &quot;ni cuo le, ying gai shi &amp;gt;&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (found2 == 1 &amp;amp;&amp;amp; found3 == 0) {
        cout &amp;lt;&amp;lt; &quot;ni cuo le, ying gai shi =&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (found2 == 1 &amp;amp;&amp;amp; found3 == 2) {
        cout &amp;lt;&amp;lt; &quot;ni cuo le, ying gai shi &amp;gt;&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (found2 == 2 &amp;amp;&amp;amp; found3 == 0) {
        cout &amp;lt;&amp;lt; &quot;ni cuo le, ying gai shi =&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else if (found2 == 2 &amp;amp;&amp;amp; found3 == 1) {
        cout &amp;lt;&amp;lt; &quot;ni cuo le, ying gai shi &amp;lt;&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    //cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;K - 小白的好数组&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定一个长度为 n 的数组，求至少需要进行多少次对一个数加 p 的操作，可以使得数组至少有 k 个数字相同。&lt;/p&gt;
&lt;h3&gt;思路:&lt;/h3&gt;
&lt;p&gt;首先可以知道，若两个数%p 的结果相同，则两个数之间一定可以通过+p 的形式边成一个数。若不同，则一定不行。
因此，可以根据此条件分成 p 个组，在每一组中排完序后，可能的最小的答案一定是连续的。因此，只需要以滑动窗口的形式来寻找答案即可。
时间复杂度：O(n)。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const int MAXN = 6e7;
const double eps = 1e-5;
const ll mod = 998244353;

ll n, k, p;

void solve ()
{
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k &amp;gt;&amp;gt; p;
    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; a(p);
    for (int i = 0; i &amp;lt; n; i++) {
        ll t;
        cin &amp;gt;&amp;gt; t;
        a[t % p].push_back(t);
    }

    bool found = false;
    ll ans = LLONG_MAX;
    for (int i = 0; i &amp;lt; p; i++) {
        if (a[i].size() &amp;lt; k) continue;
        else found = true;
        sort(a[i].begin(), a[i].end());

        ll mn = 0;
        for (int j = 0; j &amp;lt; k - 1; j++) {
            mn += (a[i][k - 1] - a[i][j]) / p;
        }

        ans = min(ans, mn);
        ll l = 1, r = k;
        while (r &amp;lt; a[i].size()) {
            mn -= (a[i][r - 1] - a[i][l - 1]) / p;
            mn += (a[i][r] - a[i][r - 1]) / p * (k - 1);
            ans = min(mn, ans);
            l++;
            r++;
        }
    }

    if (!found) {
        cout &amp;lt;&amp;lt; &quot;wuwuwu&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
    }else {
        cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
    }
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    //cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;B - 小李吃豆子&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定一个在 1e12 内的 n，求有多少个连续的数列相加后等于 n。&lt;/p&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;对于任意 n，假设其连续数列为 p，p + 1, p + 2,..., p + k - 1。对其求和后即可得到：(2p + k - 1) * k / 2 = n。化简后即为：p = (2n / k - k + 1) / 2。即一个符合要求的 p，一定会满足以下两个条件：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2n % k == 0&lt;/li&gt;
&lt;li&gt;(2n / k - k + 1) % 2 == 0&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;因为范围为 1e12，考虑优化。2n / k - k + 1 &amp;gt;= 0 的条件为 p &amp;gt;= sqrt(2n)，即只需遍历 sqrt(2n)内的数即可。
时间复杂度：O(sqrt(2n))。&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
    cin &amp;gt;&amp;gt; n;
    ll m = sqrtl(2 * n);

    ll ans = 0;
    for (int i = 1; i &amp;lt;= m; i++) {
        if ((2 * n) % i == 0 &amp;amp;&amp;amp; ((2 * n) / i - i + 1) % 2 == 0) {
            ans++;
        }
    }
    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;I - 攻守兼备&lt;/h2&gt;
&lt;h3&gt;题意：&lt;/h3&gt;
&lt;p&gt;给定 n 张卡牌，每张卡牌有攻击力和防御值。想要从这 n 张卡牌中找到两张卡，使得这两张卡的总攻击力和总防御力的最小值达到最大，输出总攻击力和总防御力的最小值的最大值。&lt;/p&gt;
&lt;h3&gt;思路：&lt;/h3&gt;
&lt;p&gt;这里采用贪心做法。具体思路见&lt;a href=&quot;https://blog.wustacm.org/2025/12/15/2025%E8%8F%9C%E9%B8%9F%E6%9D%AF%E9%A2%98%E8%A7%A3/#%E8%B4%AA%E5%BF%83&quot;&gt;wustacm&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;代码：&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair&amp;lt;ll, ll&amp;gt;;

#define fi first
#define se second

const ll MAXN = 1e7;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
    cin &amp;gt;&amp;gt; n;
    vector &amp;lt;pi&amp;gt; v(n);
    for (int i = 0; i &amp;lt; n; i++) {
        cin &amp;gt;&amp;gt; v[i].fi &amp;gt;&amp;gt; v[i].se;
    }
    sort(v.begin(), v.end(), [] (auto a1, auto b1) {
        return abs(a1.fi - a1.se) &amp;lt; abs(b1.fi - b1.se);
    });

    ll ans = 0, maxfi = 0, maxse = 0;
    for (int i = 0; i &amp;lt; n; i++) {
        if (v[i].fi &amp;gt; v[i].se) {
            ans = max(ans, maxse + v[i].se);
        }else {
            ans = max(ans, maxfi + v[i].fi);
        }
        maxfi = max(maxfi, v[i].fi);
        maxse = max(maxse, v[i].se);
    }

    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin &amp;gt;&amp;gt; _;
    while (_--) {
        solve();
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>华中农业大学第十五届程序设计竞赛（新生赛）游记及部分题解</title><link>https://blog.everlasting.xin/posts/2025_hzau_freshman_contest/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/2025_hzau_freshman_contest/</guid><description>记录我参加华中农业大学第十五届程序设计竞赛新生赛的经历，以及部分题目的题解和代码。</description><pubDate>Tue, 09 Dec 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;华中农业大学第十五届程序设计竞赛（新生赛）游记及部分题解&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;仅以此记录我的第一次程序设计线下赛&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;游记&lt;/h2&gt;
&lt;p&gt;第一次线下赛，不出意料的感觉晚上没睡好，但到了比赛场地后就毫无疲惫感而言了。&lt;s&gt;（瑞幸的新品是真难喝）&lt;/s&gt;&lt;/p&gt;
&lt;p&gt;到场签到领了伴手礼，一个ACM的笔记本和一张明信片，虽然有点不及预期，但第一次拿到周边物件还是很兴奋的。在这里还是得感谢志愿者，赛前领的小纸条一下就弄丢了，上面的帐号密码志愿者们很热情地帮我解决了，非常感谢！另外赛前统一发的小熊猫dev还是很好用的，避免了用电脑自带的devc++，好评！&lt;/p&gt;
&lt;p&gt;比赛开始后，很幸运地快速发现了签到题L，拿了一个一血！交完显示“correct”的时候发现自己是一血还是非常兴奋的！之后看了眼D题，发现跟热身赛的题差不多一样（&lt;s&gt;其实并非&lt;/s&gt;），写完wa了之后，看到榜上有不少人也wa了D，就觉得有点不对劲了，仔细看题发现只能删除长度大于一的字串，找了下规律后又交了一发，wa了之后就没碰D题了(赛后题解显示是一道恐怖的分类讨论)。&lt;/p&gt;
&lt;p&gt;接下来值得说的就是C题，赛时看出来是单调栈很兴奋，快速敲完交了一发wa后，由于没读清题意，自己一直在那乱改，交了无数发，最后十分钟实在没招了，而且此时也对题目思考地比较深入，再把第一发wa去掉特判后交了一发竟然A了~~(真的感受到了救赎感)~~，但是白白在这道题浪费了一个多小时，赛后看来很有可能可以再开一题，也是很可惜了。&lt;/p&gt;
&lt;p&gt;另外，赛中发的午饭是一个“冷”热狗，鸡腿和两根香肠，难吃。&lt;/p&gt;
&lt;p&gt;最后还是凭借7题获得了金牌，但以993的罚时在7题尾。就本次比赛来说，一定要想清楚题目再交，下次不能 “样例过了就AC” 了。&lt;/p&gt;
&lt;p&gt;&amp;lt;br&amp;gt;&lt;/p&gt;
&lt;h2&gt;部分题解&lt;/h2&gt;
&lt;h4&gt;L - 山海之约&lt;/h4&gt;
&lt;h5&gt;题意：&lt;/h5&gt;
&lt;p&gt;给定两个非负整数 a 与 b，判断它们的和是否为神秘数字 350234。&lt;/p&gt;
&lt;h5&gt;代码：&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

void solve ()
{
	ll a, b;
	cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b;
	if (a + b == 350234) {
            cout &amp;lt;&amp;lt; &quot;YES&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
	}else {
		cout &amp;lt;&amp;lt; &quot;NO&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
	}
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;H - 对决&lt;/h4&gt;
&lt;h5&gt;题意：&lt;/h5&gt;
&lt;p&gt;给定两个字符串 s 与 t，记字串“fire”出现次数是a，“water”出现次数是b， “wind”出现次数是c，定义字符串的权值为a + b * c，判断s的权值是否严格大于t的权值。&lt;/p&gt;
&lt;h5&gt;思路：&lt;/h5&gt;
&lt;p&gt;简单遍历即可。
时间复杂度：O(n + m)。&lt;/p&gt;
&lt;h5&gt;代码：&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n, m;

void solve ()
{
	string a = &quot;fire&quot;;
	string b = &quot;water&quot;;
	string c = &quot;wind&quot;;
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
	string s, t;
	cin &amp;gt;&amp;gt; s &amp;gt;&amp;gt; t;
	
	ll cnta = 0;
	ll cntb = 0;
	ll cntc = 0;
	for (int i = 0; i &amp;lt;= n - 4; i++) {
		if (s[i] == &apos;f&apos; &amp;amp;&amp;amp; s[i + 1] == &apos;i&apos; &amp;amp;&amp;amp; s[i + 2] == &apos;r&apos; &amp;amp;&amp;amp; s[i + 3] == &apos;e&apos;) {
			cnta++;
		}
		if (s[i] == &apos;w&apos; &amp;amp;&amp;amp; s[i + 1] == &apos;i&apos; &amp;amp;&amp;amp; s[i + 2] == &apos;n&apos; &amp;amp;&amp;amp; s[i + 3] == &apos;d&apos;) {
			cntc++;
		}
	}
	for (int i = 0; i &amp;lt;= n - 5; i++) {
		if (s[i] == &apos;w&apos; &amp;amp;&amp;amp; s[i + 1] == &apos;a&apos; &amp;amp;&amp;amp; s[i + 2] == &apos;t&apos; &amp;amp;&amp;amp; s[i + 3] == &apos;e&apos; &amp;amp;&amp;amp; s[i + 4] == &apos;r&apos;) {
			cntb++;
		}
	}
	
	ll cntaa = 0;
	ll cntbb = 0;
	ll cntcc = 0;
	
	for (int i = 0; i &amp;lt;= m - 4; i++) {
		if (t[i] == &apos;f&apos; &amp;amp;&amp;amp; t[i + 1] == &apos;i&apos; &amp;amp;&amp;amp; t[i + 2] == &apos;r&apos; &amp;amp;&amp;amp; t[i + 3] == &apos;e&apos;) {
			cntaa++;
		}
		if (t[i] == &apos;w&apos; &amp;amp;&amp;amp; t[i + 1] == &apos;i&apos; &amp;amp;&amp;amp; t[i + 2] == &apos;n&apos; &amp;amp;&amp;amp; t[i + 3] == &apos;d&apos;) {
			cntcc++;
		}
	}
	for (int i = 0; i &amp;lt;= m - 5; i++) {
		if (t[i] == &apos;w&apos; &amp;amp;&amp;amp; t[i + 1] == &apos;a&apos; &amp;amp;&amp;amp; t[i + 2] == &apos;t&apos; &amp;amp;&amp;amp; t[i + 3] == &apos;e&apos; &amp;amp;&amp;amp; t[i + 4] == &apos;r&apos;) {
			cntbb++;
		}
	}
	
	if (cnta + cntb * cntc &amp;gt; cntaa + cntbb * cntcc) {
		cout &amp;lt;&amp;lt; &quot;YES&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
	}else {
		cout &amp;lt;&amp;lt; &quot;NO&quot; &amp;lt;&amp;lt; &apos;\n&apos;;
	}
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;I - 学霸题&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定三个点 A, B, C，找出一个点D使得这 4 个点可以连成一个平行四边形。&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;确定两个点，求出两点间x和y座标的变化后根据第三个点推出第四个点的位置。
时间复杂度：O(1)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

void solve ()
{
	ll x1, y1, x2, y2, x3, y3;
	cin &amp;gt;&amp;gt; x1 &amp;gt;&amp;gt; y1 &amp;gt;&amp;gt; x2 &amp;gt;&amp;gt; y2 &amp;gt;&amp;gt; x3 &amp;gt;&amp;gt; y3;
	ll tx = x2 - x1;
	ll ty = y2 - y1;
	ll x4 = x3 + tx;
	ll y4 = y3 + ty;
	cout &amp;lt;&amp;lt; x4 &amp;lt;&amp;lt; &apos; &apos; &amp;lt;&amp;lt; y4 &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;B - 爱的魔法&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定一个序列，对于序列中的每一个数，交换至多两个数位，最大化操作后的序列和。&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;数据范围不是很大，直接对每一个数简单遍历，取每个数的最大值即可。
时间复杂度：O(n)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
	cin &amp;gt;&amp;gt; n;
	vector &amp;lt;ll&amp;gt; v(n);
	for (int i = 0; i &amp;lt; n; i++) {
		cin &amp;gt;&amp;gt; v[i];
	}
	
	for (int i = 0; i &amp;lt; n; i++) {
		string s = to_string(v[i]);
		for (int k = 0; k &amp;lt; (ll)s.size(); k++) {
			ll t = s[k] - &apos;0&apos;;
			ll pos = k;
			for (ll j = k + 1; j &amp;lt; (ll)s.size(); j++) {
				ll a = s[j] - &apos;0&apos;;
				if (a &amp;gt;= t) {
					t = a;
					pos = j;				
				}
			}
			if (pos != k &amp;amp;&amp;amp; s[pos] &amp;gt; s[k]) {
				swap(s[pos], s[k]);
				break;
			}
		}
		v[i] = stoll(s);
	}
	
	ll ans = 0;
	for (int i = 0; i &amp;lt; n; i++) {
		ans += v[i];
	}
	
	cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;A - 矩形游戏&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定一个&lt;strong&gt;单调不降&lt;/strong&gt;的序列[b&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;, b&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, ... b&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;]与一个k行n列的矩阵A。签到哥从矩阵的第一行第一列移动到第k行的任意一列。签到哥位于(i, j)时可以移动到(i + 1, j - 1)或(i + 1, j)或(i + 1, j + 1)。签到哥只能移动到大于等于自己的位置，且移动后签到哥的体力也会相应增加。&lt;/p&gt;
&lt;p&gt;求签到哥到达第k行的体力最大值&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;由于序列单调不降，只需尽量往右走就行。另外，由于k是1e9级别，而n是2e5级别，最后如果到最后一列可以直接退出单独计算。
时间复杂度：O(n)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll k, n;

void solve ()
{
	cin &amp;gt;&amp;gt; k &amp;gt;&amp;gt; n;
	vector &amp;lt;ll&amp;gt; v(n);
	for (int i = 0; i &amp;lt; n; i++) {
		cin &amp;gt;&amp;gt; v[i];
	}
	
	ll sum = 0;
	ll j = 0;
	ll t = 0;
	for (int i = 0; i &amp;lt; k; i++) {
		if (sum &amp;gt;= v[j + 1] &amp;amp;&amp;amp; j &amp;lt; n - 1) {
			j++;
		}
		sum += v[j];
		if (j == n - 1) {
			t = k - i - 1;
			break;
		}
	}
	
	sum += max(0LL, t) * v[n - 1];
	cout &amp;lt;&amp;lt; sum &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;M - 终极考验&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定n个石柱高度，耗费一点能量可以使任意一个i至min(i + x - 1, n)区间内的所有石柱升高1米。&lt;/p&gt;
&lt;p&gt;求使得石柱的高度单调不降所要耗费能量的最小值。&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;这里给出一个另类的思路。对于任意一个v&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;，在（i - x + 1， i）这个区间内若存在v&amp;lt;sub&amp;gt;y&amp;lt;/sub&amp;gt;需要增加，则v&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;一定会与v&amp;lt;sub&amp;gt;y&amp;lt;/sub&amp;gt;增加相同次数。因此，在维护好一个差分数组后，我们可以考虑对于任意一个d&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;，加上需要做区间加且区间加触及不到d&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;的合法的d&amp;lt;sub&amp;gt;i - x&amp;lt;/sub&amp;gt;，最后加上所有小于0的d[i]的绝对值即可
时间复杂度：O(n);&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

void solve ()
{
	ll n, x;
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; x;
	vector &amp;lt;ll&amp;gt; v(n + 1, 0);
	vector &amp;lt;ll&amp;gt; d(n + 1, 0);
	for (int i = 1; i &amp;lt;= n; i++) {
		cin &amp;gt;&amp;gt; v[i];
		d[i] = v[i] - v[i - 1];
	}
	
	for (int i = x + 1; i &amp;lt;= n; i++) {
		if (d[i - x] &amp;lt; 0) {
			d[i] += d[i - x];
		}
	}
	
	ll ans = 0;
	for (int i = 2; i &amp;lt;= n; i++) {
		if (d[i] &amp;lt; 0) {
			ans += abs(d[i]);
		}
	}
	
	cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;
	
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;C - 小W的计数题&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;对于给出的每一个a&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;，找到元素数量最多的集合S&amp;lt;sub&amp;gt;x&amp;lt;/sub&amp;gt;, 其中对于任意的y∈S，使得[a&amp;lt;sub&amp;gt;min{x,y}&amp;lt;/sub&amp;gt;, ..., a&amp;lt;sub&amp;gt;max{x,y}&amp;lt;/sub&amp;gt;]的最大值为a&amp;lt;sub&amp;gt;y&amp;lt;/sub&amp;gt;。&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;题意很复杂，简要地说，这一题实际上是想要找到对于每一个a&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;向左的单调递增区间和向右的单调递增区间的长度之和。
由此，不难想到可以利用单调栈来解决问题。可以维护从前往后的一个单调递减栈和从后往前的维护一个单调递减栈，在每一位加上栈的大小，重复两遍即是最终结果。
时间复杂度：O(n)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n;

void solve ()
{
	cin &amp;gt;&amp;gt; n;
	vector &amp;lt;ll&amp;gt; v(n + 1);
	for (int i = 1; i &amp;lt;= n; i++) {
		cin &amp;gt;&amp;gt; v[i];
	}
	
	vector &amp;lt;ll&amp;gt; ans(n + 1, 0);
	stack &amp;lt;ll&amp;gt; stk;
	
	for (int i = 1; i &amp;lt;= n; i++) {
		while (!stk.empty() &amp;amp;&amp;amp; v[i] &amp;gt; stk.top()) {
			stk.pop();
		}
		stk.push(v[i]);
		ans[i] += stk.size();
	}
	
	stack &amp;lt;ll&amp;gt; stk1;
	
	for (int i = n; i &amp;gt;= 1; i--) {
		while (!stk1.empty() &amp;amp;&amp;amp; v[i] &amp;gt; stk1.top()) {
			stk1.pop();
		}
		stk1.push(v[i]);
		ans[i] += stk1.size();
	}
	
	for (int i = 1; i &amp;lt;= n; i++) {
        cout &amp;lt;&amp;lt; ans[i] - 1 &amp;lt;&amp;lt; &apos; &apos;;
	}
	cout &amp;lt;&amp;lt; &apos;\n&apos;;
	
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;G - 二分图判定&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定一个序列[a&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;, a&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, ... a&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;]和一个正整数k, 在一张包含n个点的图上，第i个点的权值为i，对于合法的任意两点i，j，若 |a&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; - a&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;| &amp;gt; k，就在i与j两点之间连接一条无向边。&lt;/p&gt;
&lt;p&gt;求出最小的非负整数k，使得按照上述方法生成的图是二分图。&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;读完题后不难发现，该题的目的是在给定的a&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;序列中，将其分为两个集合，并最小化两个集合的极差的最大值。&lt;/p&gt;
&lt;p&gt;不难想到可以利用二分答案的方法来解决这道题, 可以先对a&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;序列进行排序，再以答案进行从前到后和从后到前的check，最后若r &amp;lt;= l + 1则说明check成功。
时间复杂度：O(nlogn)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 998244353;

ll n;

void solve ()
{
    cin &amp;gt;&amp;gt; n;
    vector &amp;lt;ll&amp;gt; v(n + 1);
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; v[i];
    }
    sort(v.begin() + 1, v.end());

    auto check = [&amp;amp;] (ll md) -&amp;gt; bool {
        ll l = 1;
        for (int i = 1; i &amp;lt;= n; i++) {
            if (v[i] - v[1] &amp;lt;= md) {
                l = i;
            }else {
                break;
            } 
        }
        ll r = n;
        for (int i = n - 1; i &amp;gt;= 1; i--) {
            if (v[n] - v[i] &amp;lt;= md) {
                r = i;
            }else {
                break;
            }
        }
        return r &amp;lt;= l + 1;
    };

    ll l = 0, r = v[n]; 
    while (l &amp;lt;= r) {
        ll mid = l + ((r - l) &amp;gt;&amp;gt; 1);
        if (check(mid)) {
            r = mid - 1;
        }else {
            l = mid + 1;
        }
    }
    cout &amp;lt;&amp;lt; l &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;J - 鱼骨挖矿法&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定一个n行m列的二位网格，每个格子的数字代表当前格的矿物价值。首先钒钒会选择第i行作为主矿道，并将主矿道上方和下方的矿道的所有矿物全部采集。再以主矿道为中心，在每个满足j === 2 (mod 3)的j列（分矿道）分别向上向下挖，在挖到第一个矿物时停止挖掘。&lt;/p&gt;
&lt;p&gt;挖掘规则：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;如果在一次挖掘操作中发现多个矿物，钒钒会将这些矿物同时挖掘。&lt;/li&gt;
&lt;li&gt;如果在当前分矿道上挖掘到矿物，钒钒会立即停止挖掘&lt;/li&gt;
&lt;li&gt;上下分矿道的挖掘情况相互独立，即：上分矿道的挖掘情况不会影响到下分矿道的挖掘情况。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;求在以第i行为主矿道时(1 &amp;lt;= i &amp;lt;= n)， 所能挖到的矿物的总价值。&lt;/p&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;首先，对于每一个主矿道来说，我们可以预处理每一个主矿道的结果。而对于每一个分矿道来说，对于向上的分矿道，我们可以预处理出到每一格时所能挖到的矿物价值，即sup[i][j] = v[i][j] + v[i - 1][j] + v[i][j - 1] + v[i][j + 1]。若sup[i][j] != 0，则up[i][j] = sup[i][j]，否则up[i][j] = up[i - 1][j]。向下的分矿道也是类似的。在每个i行，只需要加上所有合法的up[i - 2][j]和dw[i + 2][j]即可。
时间复杂度：O(n * m)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 1e9 + 7;

ll n, m;

void solve ()
{
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; v(n + 3, vector &amp;lt;ll&amp;gt; (m + 3));
    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            cin &amp;gt;&amp;gt; v[i][j];
        }
    }

    vector &amp;lt;ll&amp;gt; ss(n + 2, 0);
    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            ss[i] += v[i][j];
        }
    }

    vector &amp;lt;ll&amp;gt; s(n + 2, 0);//主矿道
    for (int i = 1; i &amp;lt;= n; i++) {
        s[i] = ss[i - 1] + ss[i] + ss[i + 1];
    }

    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; sa(n + 2, vector &amp;lt;ll&amp;gt; (m + 2));//上部分矿道
    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            sa[i][j] = v[i][j] + v[i - 1][j] + v[i][j - 1] + v[i][j + 1];
        }
    }
    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; up(n + 2, vector &amp;lt;ll&amp;gt; (m + 2)); 
    for (int j = 1; j &amp;lt;= m; j++) {
        for (int i = 1; i &amp;lt;= n; i++) {
            if (sa[i][j] != 0) {
                up[i][j] = sa[i][j];
            }else {
                up[i][j] = up[i - 1][j];
            }
        }
    }

    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; sb(n + 2, vector &amp;lt;ll&amp;gt; (m + 2));//下部分矿道
    for (int i = 1; i &amp;lt;= n; i++) {
        for (int j = 1; j &amp;lt;= m; j++) {
            sb[i][j] = v[i][j] + v[i + 1][j] + v[i][j - 1] + v[i][j + 1];
        }
    }
    vector &amp;lt;vector &amp;lt;ll&amp;gt; &amp;gt; dw(n + 2, vector &amp;lt;ll&amp;gt; (m + 2)); 
    for (int j = 1; j &amp;lt;= m; j++) {
        for (int i = n; i &amp;gt;= 1; i--) {
            if (sb[i][j] != 0) {
                dw[i][j] = sb[i][j];
            }else {
                dw[i][j] = dw[i + 1][j];
            }
        }
    }

    vector &amp;lt;ll&amp;gt; ans(n + 1, 0);
    for (int i = 1; i &amp;lt;= n; i++) {
        if (i == 1) {
            ans[i] += s[i];
            if (n &amp;lt;= 2) continue;
            for (int j = 2; j &amp;lt;= m; j += 3) {
                ans[i] += dw[i + 2][j];
            }
        }else if (i == n) {
            ans[i] += s[n];
            if (n &amp;lt;= 2) continue;
            for (int j = 2; j &amp;lt;= m; j += 3) {
                ans[i] += up[i - 2][j];
            }
        }else {
            ans[i] += s[i];
            if (n &amp;lt;= 2) continue;
            for (int j = 2; j &amp;lt;= m; j += 3) {
                ans[i] += up[i - 2][j] + dw[i + 2][j];
            }
        }
    }

    for (int i = 1; i &amp;lt;= n; i++) {
        cout &amp;lt;&amp;lt; ans[i] &amp;lt;&amp;lt; &apos; &apos;;
    }
    cout &amp;lt;&amp;lt; &apos;\n&apos;;
}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;K - 大师和他的领域&lt;/h4&gt;
&lt;h5&gt;题意&lt;/h5&gt;
&lt;p&gt;给定一个数组a和值k，求有多少个区间满足以下要求：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;区间中必须包含值k&lt;/li&gt;
&lt;li&gt;区间中大于k值的数量必须等于小于k值的数量&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;思路&lt;/h5&gt;
&lt;p&gt;我们可以令大于k的值为1，小于k的值为-1，等于k的值为0。维护一个前缀和数组。对于每一个的下标，都往前二分查找相同值且包含值k的最大左边界即可。
时间复杂度：O(nlogn)。&lt;/p&gt;
&lt;h5&gt;代码&lt;/h5&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second

const ll MAXN = 1e8;
const ld eps = 1e-12;
const ll mod = 998244353;

ll n, k;
string s;

void solve ()
{
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k;
    vector &amp;lt;ll&amp;gt; v(n + 1);   
    
    for (int i = 1; i &amp;lt;= n; i++) {
        cin &amp;gt;&amp;gt; v[i];
    }

    vector &amp;lt;ll&amp;gt; s(n + 1, 0);
    for (int i = 1; i &amp;lt;= n; i++) {
        s[i] = s[i - 1];
        if (v[i] &amp;gt; k) {
            s[i]++;
        }else if (v[i] &amp;lt; k) {
            s[i]--;
        }
    }

    vector &amp;lt;vector&amp;lt;ll&amp;gt; &amp;gt; pos(2 * n + 2);
    pos[n].push_back(0);
    ll ans = 0; 
    ll exist = -1;

    for (int i = 1; i &amp;lt;= n; i++) {
        pos[s[i] + n].push_back(i);
        if (v[i] == k) {
            exist = i;
        }
        if (exist != -1) {
            ans += lower_bound(pos[s[i] + n].begin(), pos[s[i] + n].end(), exist) - pos[s[i] + n].begin();
        }
    }
    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &apos;\n&apos;;

}

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _ = 1;
	cin &amp;gt;&amp;gt; _;
	while (_--) {
		solve();
	}
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>CS50入门教程</title><link>https://blog.everlasting.xin/posts/cs50%E5%85%A5%E9%97%A8/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/cs50%E5%85%A5%E9%97%A8/</guid><description>记录 CS50 入门前的准备工作，以及课程环境配置与本地 VSCode 连接方法。</description><pubDate>Fri, 10 Oct 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;CS50入门教程&lt;/h1&gt;
&lt;h2&gt;预先准备&lt;/h2&gt;
&lt;p&gt;首先，在开始之前，面对全英文的cs50网站，准备一个浏览器的翻译插件是必要的。这里推荐根据&lt;a href=&quot;https://scandidreams.top/2025/08/31/AI%E7%BF%BB%E8%AF%91%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/&quot;&gt;AI翻译插件配置教程 | scandi-blog&lt;/a&gt;来设置。若不想太麻烦，可以先选择有道灵动翻译插件先体验，在之后如果感觉翻译的晦涩难懂，跟原文有偏差，可以再使用AI翻译插件。&lt;/p&gt;
&lt;p&gt;其次，由于众所周知的原因，梯子的准备会让学习的过程更加顺畅。&lt;/p&gt;
&lt;p&gt;另外，也需要注册一个github账号，并提前在电脑上安装VSCode。&lt;/p&gt;
&lt;h2&gt;关于CS50的环境配置&lt;/h2&gt;
&lt;p&gt;CS50的学习主要分为看课程和提交作业两大项。关于课程的观看，可以直接在B站搜索CS50的相关课程资源来学习。观看一节课程，提交一节作业。&lt;/p&gt;
&lt;p&gt;提交作业即需要配置相关的环境了。再点击进入csdiy中的2025年课程后，下滑左侧栏，找到Week 1 C，点击进入。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/cs50/1.png&quot; alt=&quot;CS50 课程页面&quot; /&gt;&lt;/p&gt;
&lt;p&gt;点开后，下滑右侧栏至底部，找到Problem Set 1（作业集1）。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/cs50/2.png&quot; alt=&quot;CS50 Problem Set 1 入口&quot; /&gt;&lt;/p&gt;
&lt;p&gt;点击进入后，便可看到配置环境的一些步骤。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/cs50/3.png&quot; alt=&quot;CS50 环境配置步骤&quot; /&gt;&lt;/p&gt;
&lt;p&gt;首先进行步骤一，点开链接后，点击Authorize cs50（授权cs50）后，可退回进行步骤2。&lt;/p&gt;
&lt;p&gt;进入&lt;a href=&quot;https://cs50.dev&quot;&gt;CS50.dev &lt;/a&gt;后，使用github账号log in后，便可看到网页版的VSCode。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/cs50/4.png&quot; alt=&quot;CS50 网页版 VSCode&quot; /&gt;&lt;/p&gt;
&lt;p&gt;但是在这个网页上做CS50的作业是非常卡顿的。若将其连接到本地VSCode，卡顿的情况将会大大改善。&lt;/p&gt;
&lt;h4&gt;将 CS50 网页端的 VSCode 环境连接到本地 VSCode&lt;/h4&gt;
&lt;p&gt;打开电脑中下载的VSCode软件，安装GitHub Codespaces扩展，成功后会发现左侧栏出现新标识（远程资源管理器），点击进入，并登录github账号，便可将网页端的VSCode连接到本地，此后可以愉快的在本地写CS50的作业啦！前提是每次连接前需要进入&lt;a href=&quot;https://cs50.dev&quot;&gt;CS50.dev &lt;/a&gt;打开网页端。&lt;/p&gt;
&lt;p&gt;祝大家学习愉快！&lt;/p&gt;
</content:encoded></item><item><title>Markdown Extended Features</title><link>https://blog.everlasting.xin/posts/markdown-extended/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/markdown-extended/</guid><description>Read more about Markdown features in Fuwari</description><pubDate>Wed, 01 May 2024 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;GitHub Repository Cards&lt;/h2&gt;
&lt;p&gt;You can add dynamic cards that link to GitHub repositories, on page load, the repository information is pulled from the GitHub API.&lt;/p&gt;
&lt;p&gt;::github{repo=&quot;Fabrizz/MMM-OnSpotify&quot;}&lt;/p&gt;
&lt;p&gt;Create a GitHub repository card with the code &lt;code&gt;::github{repo=&quot;&amp;lt;owner&amp;gt;/&amp;lt;repo&amp;gt;&quot;}&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;::github{repo=&quot;saicaca/fuwari&quot;}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Admonitions&lt;/h2&gt;
&lt;p&gt;Following types of admonitions are supported: &lt;code&gt;note&lt;/code&gt; &lt;code&gt;tip&lt;/code&gt; &lt;code&gt;important&lt;/code&gt; &lt;code&gt;warning&lt;/code&gt; &lt;code&gt;caution&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;:::note
Highlights information that users should take into account, even when skimming.
:::&lt;/p&gt;
&lt;p&gt;:::tip
Optional information to help a user be more successful.
:::&lt;/p&gt;
&lt;p&gt;:::important
Crucial information necessary for users to succeed.
:::&lt;/p&gt;
&lt;p&gt;:::warning
Critical content demanding immediate user attention due to potential risks.
:::&lt;/p&gt;
&lt;p&gt;:::caution
Negative potential consequences of an action.
:::&lt;/p&gt;
&lt;h3&gt;Basic Syntax&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;:::note
Highlights information that users should take into account, even when skimming.
:::

:::tip
Optional information to help a user be more successful.
:::
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Custom Titles&lt;/h3&gt;
&lt;p&gt;The title of the admonition can be customized.&lt;/p&gt;
&lt;p&gt;:::note[MY CUSTOM TITLE]
This is a note with a custom title.
:::&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::note[MY CUSTOM TITLE]
This is a note with a custom title.
:::
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;GitHub Syntax&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;[!TIP]
&lt;a href=&quot;https://github.com/orgs/community/discussions/16925&quot;&gt;The GitHub syntax&lt;/a&gt; is also supported.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; [!NOTE]
&amp;gt; The GitHub syntax is also supported.

&amp;gt; [!TIP]
&amp;gt; The GitHub syntax is also supported.
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Spoiler&lt;/h3&gt;
&lt;p&gt;You can add spoilers to your text. The text also supports &lt;strong&gt;Markdown&lt;/strong&gt; syntax.&lt;/p&gt;
&lt;p&gt;The content :spoiler[is hidden &lt;strong&gt;ayyy&lt;/strong&gt;]!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;The content :spoiler[is hidden **ayyy**]!

&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>Expressive Code Example</title><link>https://blog.everlasting.xin/posts/expressive-code/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/expressive-code/</guid><description>How code blocks look in Markdown using Expressive Code.</description><pubDate>Wed, 10 Apr 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Here, we&apos;ll explore how code blocks look using &lt;a href=&quot;https://expressive-code.com/&quot;&gt;Expressive Code&lt;/a&gt;. The provided examples are based on the official documentation, which you can refer to for further details.&lt;/p&gt;
&lt;h2&gt;Expressive Code&lt;/h2&gt;
&lt;h3&gt;Syntax Highlighting&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://expressive-code.com/key-features/syntax-highlighting/&quot;&gt;Syntax Highlighting&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Regular syntax highlighting&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;console.log(&apos;This code is syntax highlighted!&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Rendering ANSI escape sequences&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;ANSI colors:
- Regular: [31mRed[0m [32mGreen[0m [33mYellow[0m [34mBlue[0m [35mMagenta[0m [36mCyan[0m
- Bold:    [1;31mRed[0m [1;32mGreen[0m [1;33mYellow[0m [1;34mBlue[0m [1;35mMagenta[0m [1;36mCyan[0m
- Dimmed:  [2;31mRed[0m [2;32mGreen[0m [2;33mYellow[0m [2;34mBlue[0m [2;35mMagenta[0m [2;36mCyan[0m

256 colors (showing colors 160-177):
[38;5;160m160 [38;5;161m161 [38;5;162m162 [38;5;163m163 [38;5;164m164 [38;5;165m165[0m
[38;5;166m166 [38;5;167m167 [38;5;168m168 [38;5;169m169 [38;5;170m170 [38;5;171m171[0m
[38;5;172m172 [38;5;173m173 [38;5;174m174 [38;5;175m175 [38;5;176m176 [38;5;177m177[0m

Full RGB colors:
[38;2;34;139;34mForestGreen - RGB(34, 139, 34)[0m

Text formatting: [1mBold[0m [2mDimmed[0m [3mItalic[0m [4mUnderline[0m
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Editor &amp;amp; Terminal Frames&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://expressive-code.com/key-features/frames/&quot;&gt;Editor &amp;amp; Terminal Frames&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Code editor frames&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;console.log(&apos;Title attribute example&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!-- src/content/index.html --&amp;gt;
&amp;lt;div&amp;gt;File name comment example&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Terminal frames&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;echo &quot;This terminal frame has no title&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;Write-Output &quot;This one has a title!&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Overriding frame types&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;echo &quot;Look ma, no frame!&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;# Without overriding, this would be a terminal frame
function Watch-Tail { Get-Content -Tail 20 -Wait $args }
New-Alias tail Watch-Tail
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Text &amp;amp; Line Markers&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://expressive-code.com/key-features/text-markers/&quot;&gt;Text &amp;amp; Line Markers&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Marking full lines &amp;amp; line ranges&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;// Line 1 - targeted by line number
// Line 2
// Line 3
// Line 4 - targeted by line number
// Line 5
// Line 6
// Line 7 - targeted by range &quot;7-8&quot;
// Line 8 - targeted by range &quot;7-8&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Selecting line marker types (mark, ins, del)&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;function demo() {
  console.log(&apos;this line is marked as deleted&apos;)
  // This line and the next one are marked as inserted
  console.log(&apos;this is the second inserted line&apos;)

  return &apos;this line uses the neutral default marker type&apos;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Adding labels to line markers&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;// labeled-line-markers.jsx
&amp;lt;button
  role=&quot;button&quot;
  {...props}
  value={value}
  className={buttonClassName}
  disabled={disabled}
  active={active}
&amp;gt;
  {children &amp;amp;&amp;amp;
    !active &amp;amp;&amp;amp;
    (typeof children === &apos;string&apos; ? &amp;lt;span&amp;gt;{children}&amp;lt;/span&amp;gt; : children)}
&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Adding long labels on their own lines&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;// labeled-line-markers.jsx
&amp;lt;button
  role=&quot;button&quot;
  {...props}

  value={value}
  className={buttonClassName}

  disabled={disabled}
  active={active}
&amp;gt;

  {children &amp;amp;&amp;amp;
    !active &amp;amp;&amp;amp;
    (typeof children === &apos;string&apos; ? &amp;lt;span&amp;gt;{children}&amp;lt;/span&amp;gt; : children)}
&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Using diff-like syntax&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;+this line will be marked as inserted
-this line will be marked as deleted
this is a regular line
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+this is an actual diff file
-all contents will remain unmodified
 no whitespace will be removed either
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Combining syntax highlighting with diff-like syntax&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;  function thisIsJavaScript() {
    // This entire block gets highlighted as JavaScript,
    // and we can still add diff markers to it!
-   console.log(&apos;Old code to be removed&apos;)
+   console.log(&apos;New and shiny code!&apos;)
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Marking individual text inside lines&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;function demo() {
  // Mark any given text inside lines
  return &apos;Multiple matches of the given text are supported&apos;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Regular expressions&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;console.log(&apos;The words yes and yep will be marked.&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Escaping forward slashes&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;echo &quot;Test&quot; &amp;gt; /home/test.txt
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Selecting inline marker types (mark, ins, del)&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;function demo() {
  console.log(&apos;These are inserted and deleted marker types&apos;);
  // The return statement uses the default marker type
  return true;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Word Wrap&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://expressive-code.com/key-features/word-wrap/&quot;&gt;Word Wrap&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Configuring word wrap per block&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;// Example with wrap
function getLongString() {
  return &apos;This is a very long string that will most probably not fit into the available space unless the container is extremely wide&apos;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;// Example with wrap=false
function getLongString() {
  return &apos;This is a very long string that will most probably not fit into the available space unless the container is extremely wide&apos;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Configuring indentation of wrapped lines&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;// Example with preserveIndent (enabled by default)
function getLongString() {
  return &apos;This is a very long string that will most probably not fit into the available space unless the container is extremely wide&apos;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;// Example with preserveIndent=false
function getLongString() {
  return &apos;This is a very long string that will most probably not fit into the available space unless the container is extremely wide&apos;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Collapsible Sections&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://expressive-code.com/plugins/collapsible-sections/&quot;&gt;Collapsible Sections&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// All this boilerplate setup code will be collapsed
import { someBoilerplateEngine } from &apos;@example/some-boilerplate&apos;
import { evenMoreBoilerplate } from &apos;@example/even-more-boilerplate&apos;

const engine = someBoilerplateEngine(evenMoreBoilerplate())

// This part of the code will be visible by default
engine.doSomething(1, 2, 3, calcFn)

function calcFn() {
  // You can have multiple collapsed sections
  const a = 1
  const b = 2
  const c = a + b

  // This will remain visible
  console.log(`Calculation result: ${a} + ${b} = ${c}`)
  return c
}

// All this code until the end of the block will be collapsed again
engine.closeConnection()
engine.freeMemory()
engine.shutdown({ reason: &apos;End of example boilerplate code&apos; })
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Line Numbers&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://expressive-code.com/plugins/line-numbers/&quot;&gt;Line Numbers&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Displaying line numbers per block&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;// This code block will show line numbers
console.log(&apos;Greetings from line 2!&apos;)
console.log(&apos;I am on line 3&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;// Line numbers are disabled for this block
console.log(&apos;Hello?&apos;)
console.log(&apos;Sorry, do you know what line I am on?&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Changing the starting line number&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;console.log(&apos;Greetings from line 5!&apos;)
console.log(&apos;I am on line 6&apos;)
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>Simple Guides for Fuwari</title><link>https://blog.everlasting.xin/posts/guide/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/guide/</guid><description>How to use this blog template.</description><pubDate>Mon, 01 Apr 2024 00:00:00 GMT</pubDate><content:encoded>&lt;blockquote&gt;
&lt;p&gt;Cover image source: &lt;a href=&quot;https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/208fc754-890d-4adb-9753-2c963332675d/width=2048/01651-1456859105-(colour_1.5),girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This blog template is built with &lt;a href=&quot;https://astro.build/&quot;&gt;Astro&lt;/a&gt;. For the things that are not mentioned in this guide, you may find the answers in the &lt;a href=&quot;https://docs.astro.build/&quot;&gt;Astro Docs&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Front-matter of Posts&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;---
title: My First Blog Post
published: 2023-09-09
description: This is the first post of my new Astro blog.
image: ./cover.jpg
tags: [Foo, Bar]
category: Front-end
draft: false
---
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;title&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The title of the post.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;published&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The date the post was published.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;description&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A short description of the post. Displayed on index page.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The cover image path of the post.&amp;lt;br/&amp;gt;1. Start with &lt;code&gt;http://&lt;/code&gt; or &lt;code&gt;https://&lt;/code&gt;: Use web image&amp;lt;br/&amp;gt;2. Start with &lt;code&gt;/&lt;/code&gt;: For image in &lt;code&gt;public&lt;/code&gt; dir&amp;lt;br/&amp;gt;3. With none of the prefixes: Relative to the markdown file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;tags&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The tags of the post.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;category&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The category of the post.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;draft&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;If this post is still a draft, which won&apos;t be displayed.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Where to Place the Post Files&lt;/h2&gt;
&lt;p&gt;Your post files should be placed in &lt;code&gt;src/content/posts/&lt;/code&gt; directory. You can also create sub-directories to better organize your posts and assets.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;src/content/posts/
├── post-1.md
└── post-2/
    ├── cover.png
    └── index.md
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>Markdown Example</title><link>https://blog.everlasting.xin/posts/markdown/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/markdown/</guid><description>A simple example of a Markdown blog post.</description><pubDate>Sun, 01 Oct 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;An h1 header&lt;/h1&gt;
&lt;p&gt;Paragraphs are separated by a blank line.&lt;/p&gt;
&lt;p&gt;2nd paragraph. &lt;em&gt;Italic&lt;/em&gt;, &lt;strong&gt;bold&lt;/strong&gt;, and &lt;code&gt;monospace&lt;/code&gt;. Itemized lists
look like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;this one&lt;/li&gt;
&lt;li&gt;that one&lt;/li&gt;
&lt;li&gt;the other one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that --- not considering the asterisk --- the actual text
content starts at 4-columns in.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Block quotes are
written like so.&lt;/p&gt;
&lt;p&gt;They can span multiple paragraphs,
if you like.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex., &quot;it&apos;s all
in chapters 12--14&quot;). Three dots ... will be converted to an ellipsis.
Unicode is supported. ☺&lt;/p&gt;
&lt;h2&gt;An h2 header&lt;/h2&gt;
&lt;p&gt;Here&apos;s a numbered list:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;first item&lt;/li&gt;
&lt;li&gt;second item&lt;/li&gt;
&lt;li&gt;third item&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note again how the actual text starts at 4 columns in (4 characters
from the left side). Here&apos;s a code sample:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Let me re-iterate ...
for i in 1 .. 10 { do-something(i) }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you probably guessed, indented 4 spaces. By the way, instead of
indenting the block, you can use delimited blocks, if you like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;define foobar() {
    print &quot;Welcome to flavor country!&quot;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(which makes copying &amp;amp; pasting easier). You can optionally mark the
delimited block for Pandoc to syntax highlight it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import time
# Quick, count to ten!
for i in range(10):
    # (but not *too* quick)
    time.sleep(0.5)
    print i
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;An h3 header&lt;/h3&gt;
&lt;p&gt;Now a nested list:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;First, get these ingredients:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;carrots&lt;/li&gt;
&lt;li&gt;celery&lt;/li&gt;
&lt;li&gt;lentils&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Boil some water.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Dump everything in the pot and follow
this algorithm:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; find wooden spoon
 uncover pot
 stir
 cover pot
 balance wooden spoon precariously on pot handle
 wait 10 minutes
 goto first step (or shut off burner when done)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do not bump wooden spoon or it will fall.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Notice again how text always lines up on 4-space indents (including
that last line which continues item 3 above).&lt;/p&gt;
&lt;p&gt;Here&apos;s a link to &lt;a href=&quot;http://foo.bar&quot;&gt;a website&lt;/a&gt;, to a &lt;a href=&quot;local-doc.html&quot;&gt;local
doc&lt;/a&gt;, and to a &lt;a href=&quot;#an-h2-header&quot;&gt;section heading in the current
doc&lt;/a&gt;. Here&apos;s a footnote [^1].&lt;/p&gt;
&lt;p&gt;[^1]: Footnote text goes here.&lt;/p&gt;
&lt;p&gt;Tables can look like this:&lt;/p&gt;
&lt;p&gt;size material color&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;9 leather brown
10 hemp canvas natural
11 glass transparent&lt;/p&gt;
&lt;p&gt;Table: Shoes, their sizes, and what they&apos;re made of&lt;/p&gt;
&lt;p&gt;(The above is the caption for the table.) Pandoc also supports
multi-line tables:&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;keyword text&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;red Sunsets, apples, and
other red or reddish
things.&lt;/p&gt;
&lt;p&gt;green Leaves, grass, frogs
and other things it&apos;s
not easy being.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;A horizontal rule follows.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Here&apos;s a definition list:&lt;/p&gt;
&lt;p&gt;apples
: Good for making applesauce.
oranges
: Citrus!
tomatoes
: There&apos;s no &quot;e&quot; in tomatoe.&lt;/p&gt;
&lt;p&gt;Again, text is indented 4 spaces. (Put a blank line between each
term/definition pair to spread things out more.)&lt;/p&gt;
&lt;p&gt;Here&apos;s a &quot;line block&quot;:&lt;/p&gt;
&lt;p&gt;| Line one
| Line too
| Line tree&lt;/p&gt;
&lt;p&gt;and images can be specified like so:&lt;/p&gt;
&lt;p&gt;Inline math equations go in like so: $\omega = d\phi / dt$. Display
math should get its own line and be put in in double-dollarsigns:&lt;/p&gt;
&lt;p&gt;$$I = \int \rho R^{2} dV$$&lt;/p&gt;
&lt;p&gt;$$
\begin{equation*}
\pi
=3.1415926535
;8979323846;2643383279;5028841971;6939937510;5820974944
;5923078164;0628620899;8628034825;3421170679;\ldots
\end{equation*}
$$&lt;/p&gt;
&lt;p&gt;And note that you can backslash-escape any punctuation characters
which you wish to be displayed literally, ex.: `foo`, *bar*, etc.&lt;/p&gt;
</content:encoded></item><item><title>Include Video in the Posts</title><link>https://blog.everlasting.xin/posts/video/</link><guid isPermaLink="true">https://blog.everlasting.xin/posts/video/</guid><description>This post demonstrates how to include embedded video in a blog post.</description><pubDate>Tue, 01 Aug 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Just copy the embed code from YouTube or other platforms, and paste it in the markdown file.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---
title: Include Video in the Post
published: 2023-10-19
// ...
---

&amp;lt;iframe width=&quot;100%&quot; height=&quot;468&quot; src=&quot;https://www.youtube.com/embed/5gIf0_xpFPI?si=N1WTorLKL0uwLsU_&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allowfullscreen&amp;gt;&amp;lt;/iframe&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;YouTube&lt;/h2&gt;
&lt;p&gt;&amp;lt;iframe width=&quot;100%&quot; height=&quot;468&quot; src=&quot;https://www.youtube.com/embed/5gIf0_xpFPI?si=N1WTorLKL0uwLsU_&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/p&gt;
&lt;h2&gt;Bilibili&lt;/h2&gt;
&lt;p&gt;&amp;lt;iframe width=&quot;100%&quot; height=&quot;468&quot; src=&quot;//player.bilibili.com/player.html?bvid=BV1fK4y1s7Qf&amp;amp;p=1&quot; scrolling=&quot;no&quot; border=&quot;0&quot; frameborder=&quot;no&quot; framespacing=&quot;0&quot; allowfullscreen=&quot;true&quot;&amp;gt; &amp;lt;/iframe&amp;gt;&lt;/p&gt;
</content:encoded></item></channel></rss>