题意:
改变列的相对位置,看看新的行列式是否合法
思路:
只要如果合法的话,每一列的中各行的相对位置的数对应都是不变的,,也就是我们只需要看改变前后时候存在相同的序列就是了
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
#define kuaidian ios::sync_with_stdio(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 5e4, maxd = 1e8;
const ll mod = 1e9 + 7;
const ll INF = 0x7f7f7f7f;
int n, a[10];
char s[10][10];
map<string, int> mp;
char ss[10][10] = {
"0000000",
"1001111",
"0010010",
"0000110",
"1001100",
"0100100",
"0100000",
"0001111",
"0000000",
"0000100"
};
void init() {
}
int main() {
init();
int T;
scanf("%d", &T);
while(T--) {
mp.clear();
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%s", &a[i], s[i]);
}
string s1, s2, s3, s4, s5, s6, s7;
for(int i = 0; i < n; ++i) {
s1.push_back(ss[a[i]][0]);
s2.push_back(ss[a[i]][1]);
s3.push_back(ss[a[i]][2]);
s4.push_back(ss[a[i]][3]);
s5.push_back(ss[a[i]][4]);
s6.push_back(ss[a[i]][5]);
s7.push_back(ss[a[i]][6]);
}
// cout << s1 << endl;
// cout << s2 << endl;
// cout << s3 << endl;
// cout << s4 << endl;
// cout << s5 << endl;
// cout << s6 << endl;
// cout << s7 << endl;
mp[s1]++;
mp[s2]++;
mp[s3]++;
mp[s4]++;
mp[s5]++;
mp[s6]++;
mp[s7]++;
s1.clear();
s2.clear();
s3.clear();
s4.clear();
s5.clear();
s6.clear();
s7.clear();
for(int i = 0; i < n; ++i) {
s1.push_back(s[i][0]);
s2.push_back(s[i][1]);
s3.push_back(s[i][2]);
s4.push_back(s[i][3]);
s5.push_back(s[i][4]);
s6.push_back(s[i][5]);
s7.push_back(s[i][6]);
}
// cout << s1 << endl;
// cout << s2 << endl;
// cout << s3 << endl;
// cout << s4 << endl;
// cout << s5 << endl;
// cout << s6 << endl;
// cout << s7 << endl;
int f = 0;
if(mp[s1] == 0) f = 1;
else mp[s1]--;
if(mp[s2] == 0) f = 1;
else mp[s2]--;
if(mp[s3] == 0) f = 1;
else mp[s3]--;
if(mp[s4] == 0) f = 1;
else mp[s4]--;
if(mp[s5] == 0) f = 1;
else mp[s5]--;
if(mp[s6] == 0) f = 1;
else mp[s6]--;
if(mp[s7] == 0) f = 1;
else mp[s7]--;
if(!f) puts("YES");
else puts("NO");
}
return 0;
}