CSP_202206-2_寻宝!大冒险
思路
相当于判断两个有限集合AB之间是不是满射和单射,只需要保证以下两点
- A和B元素个数相等
- A中每个元素都能通过映射\(\psi\)到B中一个元素,且\(\psi(a_1)=\psi(a_2) \iff a_1 = a_2\)
坑
输入的矩阵格式和我们平常看到的坐标系,xy轴是反过来的
#include<iostream>
using namespace std;
int main() {
int n, L, S;
scanf("%d%d%d", &n, &L, &S);
int A[n][2];
int B[S+1][S+1];
int t_in_b = 0, ans = 0; // number of trees in B
for (int i = 0; i < n; i++) {
scanf("%d%d", &A[i][0], &A[i][1]);
}
for (int i = 0; i < S+1; i++) {
for (int j = 0; j < S+1; j++) {
scanf("%d", &B[S-i][j]);
if (B[S-i][j] == 1) t_in_b++;
}
}
for (int i = 0; i < n; i++) {
// tree out of B
if (A[i][0] + S > L || A[i][1] + S > L) {
continue;
}
//
int t_in_a = 0;
for (int j = 0; j < n; j++) {
int x = A[j][0] - A[i][0];
int y = A[j][1] - A[i][1];
if (0 <= x && x <= S && 0 <= y && y <= S) t_in_a += 1;
}
if (t_in_a != t_in_b) continue; // tree num not same
bool flag = true;
for (int j = 0; j < n; j++) {
int m = A[j][0] - A[i][0];
int n = A[j][1] - A[i][1];
if (0 <= m && m <= S && 0 <= n && n <= S){
if (B[m][n] == 1) continue;
else {
flag = false;
break;
}
}
}
if (flag) ans += 1;
else continue;
}
printf("%d", ans);
return 0;
}
标签:202206,psi,int,scanf,++,CSP,大冒险
From: https://www.cnblogs.com/ticlab/p/16651248.html