CSP-S2023 题解
T1 密码锁
枚举
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 2e5 + 10;
ll a[15], c[15][15]; int n; ll b[15];
int check() {
int cnt = 0;
for (int i = 1; i <= n; i++) {
cnt = 0;
for (int j = 1; j <= 5; j++) a[j] = c[i][j];
cnt += (a[1] != b[1]) + (a[2] != b[2]) + (a[3] != b[3]) + (a[4] != b[4]) + (a[5] != b[5]);
if (cnt == 0) return 0;
else if (cnt == 1) continue;
else if (cnt >= 3) return 0;
else {
int j = 1;
for (j = 1; j <= 5 && a[j] == b[j]; j++);
if (a[j] != b[j] && a[j + 1] != b[j + 1] && (a[j] - b[j] + 10) % 10 == (a[j + 1] - b[j + 1] + 10) % 10) continue;
else return 0;
}
}
//cout << b[1] << " " << b[2] << " " << b[3] << " " << b[4] << " " << b[5] << "\n";
return 1;
}
int main() {
//freopen("lock.in", "r", stdin);
//freopen("lock.out", "w", stdout);
scanf("%d", &n); ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 5; j++) scanf("%lld", &c[i][j]);
}
for (b[1] = 0; b[1] <= 9; b[1]++) {
for (b[2] = 0; b[2] <= 9; b[2]++) {
for (b[3] = 0; b[3] <= 9; b[3]++) {
for (b[4] = 0; b[4] <= 9; b[4]++) {
for (b[5] = 0; b[5] <= 9; b[5]++) {
ans += check();
}
}
}
}
}
printf("%lld\n", ans);
return 0;
}
T2 消消乐
省流:同机房 dalao 的做法。
考虑 dp,设
则
考虑