ICPC NEAU Programming Contest 2020 J. 球衣
程序员文章站
2022-05-12 11:42:56
...
思路: 直接模拟
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
const int maxn = 105;
string a[maxn][4];
int ans1[maxn][maxn];
int ans2[maxn][maxn];
int n;
struct Color {
int x,y,z;
};
int trans(char x) {
if(x <= '9' && x >= '0') {
return x - '0';
}
else return x - 'A' + 10;
}
Color get(string x) {
int num1 = trans(x[0]) * 16 + trans(x[1]);
int num2 = trans(x[2]) * 16 + trans(x[3]);
int num3 = trans(x[4]) * 16 + trans(x[5]);
Color res = {num1,num2,num3};
return res;
}
int cal(Color x,Color y) {
return abs(x.x - y.x) + abs(x.y - y.y) + abs(x.z - y.z);
}
void init() {
memset(ans1,0,sizeof(ans1));
memset(ans2,0,sizeof(ans2));
}
void solve() {
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
if(i == j) {
ans1[i][j] = 0;
continue;
}
int flag = 0;
for(int ci = 1;ci <= 3;ci++) {
for(int cj = 1;cj <= 3;cj++) {
if(cal(get(a[i][ci]),get(a[j][cj])) >= 128) {
ans1[i][j] = ci;
flag = 1;
break;
}
}
if(flag) break;
}
}
}
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
if(i == j) {
ans2[i][j] = 0;
continue;
}
int flag = 0;
for(int cj = 1;cj <= 3;cj++) {
for(int ci = 1;ci <= 3;ci++) {
if(cal(get(a[i][ci]),get(a[j][cj])) >= 128) {
ans2[i][j] = ci;
flag = 1;
break;
}
}
if(flag) break;
}
}
}
}
void Print() {
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
printf("%d ",ans1[i][j]);
}
printf("\n");
}
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
printf("%d ",ans2[i][j]);
}
printf("\n");
}
}
int main() {
int T;scanf("%d",&T);
while(T--) {
init();
scanf("%d",&n);
for(int i = 1;i <= n;i++) {
cin >> a[i][1] >> a[i][2] >> a[i][3];
}
solve();
Print();
}
return 0;
}
上一篇: 萌新菜鸡算法笔记No.1 KMP算法 2017/8/25
下一篇: 关于排序问题