题解集合
Ryc12345678910 · · 个人记录
10.14 模拟赛
T1
题目
给出两个数
其中
题解
很简单。首先
于是就做到
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
namespace Lemon {
using ll = long long;
const int mod = 998244353;
inline void solve() {
ll l, r; cin >> l >> r;
ll ans = 0;
ll lef = 1, rig = 2;
while (lef <= r) {
if (l <= rig && lef <= r) {
ll del = 0;
if (l <= rig && rig <= r) del = -1;
ans = (ans + ((min(rig, r) - max(lef, l) + 1 + del) % mod) * (lef % mod) % mod) % mod;
}
lef *= 2, rig *= 2;
}
cout << ans << '\n';
}
}
signed main() {
IOS;
int t = 1;
cin >> t;
while (t--) Lemon::solve();
return 0;
}
:::
T2
题目
给出一个长度为
问满足:
题解
:::info[Hint1]
考虑 dp。
:::
:::info[Hint2]
设
:::info[Solution] 有显然的转移方程式:
然后注意到当前的一行仅与上一行有关,考虑压掉第一维,然后就可以写成矩阵的形式。
推出转移矩阵:
| 然后套个矩阵快速幂就好了。 |
|---|
T3
题意
给出一个内向基环树森林,然后求存不存在合法的解,使得每个点再经过
题解
exCRT 板板题,代码实现比较()。
题目的条件能够转化为很多同余式,然后你要求出解
代码我没写,就不放了。嘟嘟嘟。
T4
题意
构造出一个长度小于等于
-
- 定义一个序列为“好”的序列,当且仅当它可以表示成两个相同的序列拼接而成时。序列
a 的子序列中“好”的序列个数必须为n 。
题解
考虑我们构造的字符串
- 前半部分是一个排列
q ,包含t 个互不相同的字符1,2,\dots,t ; - 后半部分是
1,2,\dots,t 的升序排列。
每个字符
然后考虑递归构造这个序列。
我们直接对
:::success[Code]
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
namespace Lemon {
using ll = long long;
const int N = 205;
int cnt;
int p[N], q[N];
inline void work(ll n) {
if (!n) return;
if (~n & 1) q[++q[0]] = cnt++, work(n - 1);
else p[++p[0]] = cnt++, work(n >> 1);
}
inline void solve() {
ll n; cin >> n;
work(n);
cout << cnt + 100 << '\n';
for (int i = 1; i <= q[0]; i++) cout << cnt - q[i] << " ";
for (int i = p[0]; i; i--) cout << cnt - p[i] << " ";
for (int i = 1; i <= 100; i++) cout << i << " ";
}
}
signed main() {
freopen("happiest.in", "r", stdin);
freopen("happiest.out", "w", stdout);
IOS;
int t = 1;
// cin >> t;
while (t--) Lemon::solve();
return 0;
}
:::
CF1529C
题意
给每个顶点
题解
考虑树形 DP。
首先有个显然的性质,就是对于每个顶点,你选择的值必然为
根据这一点设计树形 DP。
然后转移方程也很好推,由于我不会用
:::success[Code]
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
namespace Lemon {
using ll = long long;
const int N = 1e5 + 5;
const ll inf = 1e18;
ll f[N], g[N]; // f -> max g -> min
ll l[N], r[N];
vector<int> e[N];
inline void dfs(int u, int fa) {
for (int v : e[u]) {
if (v == fa) continue;
dfs(v, u);
f[u] += max(f[v] + abs(r[u] - r[v]), g[v] + abs(r[u] - l[v]));
g[u] += max(f[v] + abs(l[u] - r[v]), g[v] + abs(l[u] - l[v]));
}
}
inline void solve() {
int n; cin >> n;
for (int i = 1; i <= n; i++) {
e[i].clear();
f[i] = 0, g[i] = 0;
cin >> l[i] >> r[i];
}
for (int i = 1; i < n; i++) {
int u, v; cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1, 0);
cout << max(f[1], g[1]) << '\n';
}
}
signed main() {
IOS;
int t = 1;
cin >> t;
while (t--) Lemon::solve();
return 0;
}
:::