总结
手速场...像我这种没手速的就直接炸了...
辣鸡 E 题交互,少打了个 ?
调了半个小时...
到最后没时间 G 题题都没看就结束了...结果早上起来被告知是阿狸的打字机...看了看题一毛一样...
提供翻译造福人类...
A. There Are Two Types Of Burgers
Description
你有 (b) 片面包,(p) 块牛肉,(f) 块鸡肉。两片面包和一块肉可以组成一个汉堡,两种汉堡的价钱分别是 (h,c)。求最大收益。(t) 组询问。
(1leq t,b,p,f,h,cleq 100)
Solution
不用贪心,直接枚举多少个鸡肉汉堡多少个牛肉汉堡,判断面包是否够用即可。
Code
#include <bits/stdc++.h>
using namespace std;
int t, b, p, f, h, c, ans;
int main() {
scanf("%d", &t);
while (t--) {
ans = 0;
scanf("%d%d%d%d%d", &b, &p, &f, &h, &c);
for (int i = 0; i <= p; i++)
for (int j = 0; j <= f; j++)
if (i+j <= b/2)
ans = max(ans, i*h+c*j);
printf("%d
", ans);
}
return 0;
}
B. Square Filling
Description
给你一个 (n imes m) 的空白棋盘,每次你可以选择一个 (2 imes 2) 的矩阵染色。问你是否能染成目标状态,输出方案(不用求最优解)。
(1leq n,mleq 50)
Solution
对于目标棋盘中的某一块黑色,一定只能由四种方法使他变黑。
那么对于每个黑块,直接枚举染它的矩阵的左上角,看这四种方案中是否有可行的。即这个 (2 imes 2) 的矩阵在目标棋盘中都为黑色,若可行,标记输出;若都不可行,显然无解。
Code
#include <bits/stdc++.h>
using namespace std;
int n, m, a[55][55], tmp;
int ans[55][55], tot;
void noans() {
puts("-1"); exit(0);
}
bool color(int x, int y) {
if (x == n || y == m || x == 0 || y == 0) return false;
if (!a[x][y] || !a[x+1][y] || !a[x][y+1] || !a[x+1][y+1]) return false;
ans[x][y] = 1;
return true;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j])
if (color(i-1, j-1) || color(i, j-1) || color(i-1, j) || color(i, j));
else noans();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
tot += ans[i][j];
printf("%d
", tot);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (ans[i][j])
printf("%d %d
", i, j);
return 0;
}
C. Gas Pipeline
Description
一条长度为 (n) 的路,让你在路上架管道,管道高度 (>) 马路高度,马路高度只为 (0) 或 (1),管道高度只能为 (1) 或 (2)。并且管道开始和结束高度为 (1)。
如果在 (x) 处要修改管道高度,那么花费管道长度为 (2),否则为 (1)。同时管道需要柱子支撑,长度为 (n) 的管道需要 (n+1) 根柱子,柱子长度取决于相邻的部分的最大高度。
单位长度管道花费 (a),单位长度柱子花费为 (b)。求最小花费。
(2leq nleq 2cdot 10^5,1leq a,bleq 10^8)
Solution
令 (f_{i,0/1}) 表示修管道 (1sim i),且 (i) 处管道高度为 (1/2) 的最小花费。
转移只需考虑第 (i-1) 个位置管道高度即可。注意,如果 (i) 处马路高度为 (1),那么直接将 (f_{i,0}) 赋值为 (infty)。
答案为 (f_{n,0})。
Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+5;
const ll inf = 2e15;
int t, n, a, b;
char ch[N];
ll f[N][2];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d", &n, &a, &b);
scanf("%s", ch+1);
f[1][0] = a+2ll*b;
f[1][1] = 2ll*a+2ll*b;
for (int i = 2; i <= n; i++) {
f[i][0] = min(f[i-1][0]+a+b, f[i-1][1]+2ll*a+2ll*b);
f[i][1] = min(f[i-1][1]+a+2ll*b, f[i-1][0]+2ll*a+2ll*b);
if (ch[i] == '1') f[i][0] = inf;
}
printf("%I64d
", f[n][0]);
}
return 0;
}
D. Number Of Permutations
Description
给你 (n) 个有序二元组。定义一个“坏的”二元组序列指,存在一个维度单调不降。
将这 (n) 个二元组全排列,问有多少种方法使它变得“不坏”,对 (998244353) 取模。
(1leq nleq 3cdot 10^5)
Solution
考虑间接法。
对于单一维度,我们将其排序,若连续 (x) 个数字相同,那么这 (x) 个位置可以任意排,贡献 (x!) 的方案数。
两个维度处理完之后,我们来加上多减去的部分。不过前提是原二元组序列能够排成两个维度均单调不降的序列。
那么如果排序后连续 (x) 个二元组相同,那么这 (x) 个位置可以任意排,贡献 (x!) 的方案数。
Code
#include <bits/stdc++.h>
using namespace std;
const int yzh = 998244353, N = 3e5+5;
int n, fac[N], ca[N], cb[N], ans, tmp, cnt = 1;
struct node {
int a, b;
bool operator < (const node &t) const {
return a == t.a ? b < t.b : a < t.a;
}
} x[N];
int main() {
scanf("%d", &n); fac[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i].a, &x[i].b);
fac[i] = 1ll*i*fac[i-1]%yzh;
ca[x[i].a]++, cb[x[i].b]++;
}
ans = fac[n], tmp = 1;
for (int i = 1; i <= n; i++)
tmp = 1ll*tmp*fac[ca[i]]%yzh;
(ans -= tmp) %= yzh;
tmp = 1;
for (int i = 1; i <= n; i++)
tmp = 1ll*tmp*fac[cb[i]]%yzh;
(ans -= tmp) %= yzh;
sort(x+1, x+n+1);
for (int i = 1; i <= n; i++)
if (x[i].b < x[i-1].b) {printf("%d
", (ans+yzh)%yzh); return 0; }
tmp = 1;
for (int i = 1; i <= n+1; i++)
if (x[i].a == x[i-1].a && x[i].b == x[i-1].b) ++tmp;
else {
cnt = 1ll*cnt*fac[tmp]%yzh;
tmp = 1;
}
(ans += cnt) %= yzh;
printf("%d
", (ans+yzh)%yzh);
return 0;
}
E. XOR Guessing
Description
这是一道交互题。
交互库先生成一个数 (x),你需要猜出 (x) 是多少。
你可以询问两次,你每次给出 (100) 个整数,这些整数范围和 (x) 相同,交互库会随机选出 (100) 个数中的一个,与 (x) 异或后返回。注意,所有询问的数(共 (200) 个)不能重复。询问两次后输出结果。
(xin[0,2^{14}-1])
Solution
可知 (x) 是位数为 (14) 的二进制数字(高位 (0) 补齐)。那么两次询问分别确定低的 (7) 位和高 (7) 位即可。
确定低的 (7) 位时,只需让给出的 (100) 个数低的 (7) 位均为 (0) 即可,因为 (2^7=128>100),一定能选出 (100) 个数。只需取返回值的低的 (7) 位,这和真实值的低的 (7) 位时相等的。
高位同理。
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = (1<<7)-1, tmp, ans = 0;
int b = (1<<14)-1-a;
printf("? ");
for (int i = 1; i <= 100; i++)
printf("%d%c", (i<<7), "
"[i == 100]);
fflush(stdout);
scanf("%d", &tmp);
ans += (tmp&a);
printf("? ");
for (int i = 1; i <= 100; i++)
printf("%d%c", i, "
"[i == 100]);
fflush(stdout);
scanf("%d", &tmp);
ans += (tmp&b);
printf("! %d
", ans);
fflush(stdout);
return 0;
}
F. Remainder Problem
Description
让你维护长度为 (500000) 的序列,支持 (q) 次操作:
- 单点加;
- 询问:(500000) 个位置模 (x) 余 (y) 的位置的值的和。
(1leq qleq 500000)
Solution
发现 (500000^{1.5}) 大概等于三亿多...发现时限 (4s),就喜闻乐见的分块了。
维护数组 (cal[x][y]),表示模 (x) 余 (y) 的位置的值的和。只需开到 (sqrt{500000}) 的大小就行了。
较大的值直接在原数组上枚举。
修改和询问复杂度是 (O(sqrt{500000})) 的,查表的话是 (O(1)) 的。
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 500000+5;
int cal[710][710], a[N], q, t, x, y;
int main() {
scanf("%d", &q);
while (q--) {
scanf("%d%d%d", &t, &x, &y);
if (t == 1) {
a[x] += y;
for (int i = 1; i <= 709; i++)
cal[i][x%i] += y;
} else {
if (x <= 709) printf("%d
", cal[x][y]);
else {
int ans = 0;
for (int i = 0; i*x+y <= 500000; i++)
ans += a[i*x+y];
printf("%d
", ans);
}
}
}
return 0;
}
G. Indie Album
生成 (n) 个字符串。生成方式为
- 新取一个字符;
- 将前面某个字符串复制后,在末尾新添一个字符。
字符集为小写字母。(q) 组询问,问串 (t) 在某个串中出现了多少次。
(1leq n,q,sum|t|leq 4cdot 10^5)
Solution
Code
我太懒了...