Files
python/GESP/资料/灰阶图像/新文件1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

115 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 256;
int b[N];
int toDec(char a, char b) {
int res = 0;
if (a >= 'A' && a <= 'F')
res += (a + 10 - 'A') * 16;
else
res += (a - '0') * 16;
if (b >= 'A' && b <= 'F')
res += b + 10 - 'A';
else
res += b - '0';
return res;
}
string toHex(int x) {
int a = x % 16;
int b = x / 16;
char c1, c2;
if (a >= 10)
c1 = 'A' + a - 10;
else
c1 = a + '0';
if (b >= 10)
c2 = 'A' + b - 10;
else
c2 = b + '0';
string res;
res.push_back(c2);
res.push_back(c1);
return res;
}
vector<string>q;
//struct Node {
// int id;
// int cnt;
// const bool operator<(const Node &b)const {
// if (cnt == b.cnt)
// return id < b.id;
// return cnt > b.cnt;
// }
//};
//Node迟到了,让副评审来吧!
vector<int>vec;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
q.push_back(s);
for (int j = 0; j < s.size(); j += 2) {
char c1, c2;
c1 = s[j], c2 = s[j + 1];
int k = toDec(c1, c2);
b[k]++;
}
}
// 选举开始~~~
// 现在,向我们走来的是很多个,由256(也可能更少)个种类的选手!
// 我们要选出其中最多的16个种族!
//裁判是vec<node>!
// vec<node>不在时,裁判就是用两个for,1个mx集团
//(包括mx最大值,mx_id最大值的编号)
//和一个vec<int>!
//开始吧!
// for (int i = 0; i <= 255; i++)
// if (b[i])
// vec.push_back({i, b[i]});
//为了防止有色块冒充,先筛一遍,然后录入选手名单!
// sort(vec.begin(), vec.end());
//由大到小排序!
// 我们输出前十六个!
for (int i = 0; i < 16; i++) {
int mx, mx_id;
mx = 0, mx_id = -1;
for (int j = 0; j < 256; j++)
if (b[j] > mx) {
mx = b[j];
mx_id = j;
}
vec.push_back(mx_id);
//important!!!
b[mx_id] = -1;
//用完要标明~不能再用了
}
for (int i = 1; i <= 16; i++)
cout << toHex(vec[i]);
cout << endl;
//开启第二问~
for (int i = 0; i < n; i++) {
for (int j = 0; j < q[0].size(); j += 2) {
char c1, c2;
c1 = q[i][j], c2 = q[i][j + 1];
int x = toDec(c1, c2);
int mi = INT_MAX;
int mi_p = 0;
for (int k = 0; k < 16; k++) {
if (mi > abs(vec[k] - x)) {
mi = abs(vec[k] - x);
mi_p = k;
}
}
cout << toHex(mi_p)[1];
}
cout << endl;
}
return 0;
}