BNUZH-ACM 周赛 Round 7 - 洛谷 | 计算机科学教育新生态
C 铺设能源管道
Solution
找出大于 的最小 即可。
Code
#include <bits/stdc++.h>
using namespace std;
int n, ans = 1;
int main()
{
cin >> n;
while (ans < n)
ans *= 10;
cout << ans;
return 0;
}
D 优秀的拆分
Solution
本质上是求 的二进制转换,用位运算操作一下即可。
注意特判 为奇数时答案为 。
Code
#include <bits/stdc++.h>
using namespace std;
int n, x = (1 << 29);
int main()
{
cin >> n;
if (n & 1)
cout << "-1";
else {
while (x) {
if (n & x)
cout << x << ' ';
x >>= 1;
}
}
return 0;
}
E 报数游戏
Solution
打表发现第 个数为 。答案为 。
F 植树节
Solution
差分模板题。定义 的差分数组为 ,满足 。显然 和 是相互一一确定的。维护 就等于维护 。
对 的 区间内的每个元素加一,在 中相当于 和 。将原本在 上 的操作放在 上,就变成了 的操作。
最后由 , 求出 即可。
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, x[N], ans;
int main()
{
cin >> n;
while (n--) {
int l, r;
cin >> l >> r;
x[l]++;
x[r + 1]--;
}
ans = x[0];
for (int i = 1; i <= 1e6; i++) {
x[i] += x[i - 1];
ans = max(ans, x[i]);
}
cout << ans << endl;
return 0;
}
F 多边形
Solution
注意到数据范围 ,考虑 的 dp。
对木棍长度排序,然后枚举木棍 。
设 表示 长度和为 的木棍集合有多少种。将 的所有 相加,即为以木棍 为最长木棍时,多边形的方案数。
转移方程为
Code
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, maxn, ans;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a.begin(), a.end());
maxn = a[n];
vector<int> f(maxn + 10, 0);
f[0] = 1;
for (int i = 1; i <= n; i++) {
if (i >= 3)
for (int j = a[i] + 1; j <= maxn + 1; j++)
ans = (ans + f[j]) % mod;
for (int j = maxn + 1; j >= 0; j--) {
if (!f[j]) continue;
if (j + a[i] <= maxn)
f[j + a[i]] = (f[j + a[i]] + f[j]) % mod;
else
f[maxn + 1] = (f[maxn + 1] + f[j]) % mod;
}
}
cout << ans << endl;
return 0;
}