黄海 1 year ago
commit e0a0e102da

@ -0,0 +1,51 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int T;
int a[N];
int n;
/*
2
3
1 2 4
5
1 2 3 4 5
*/
bool check() {
//遍历a[1]~a[n]中每个数字
// 当前枚举到的数字是a[i]
// 判断当前数字a[i]是不是其它数的倍数,不需要避开自己,因为自己肯定是自己的倍数
// 找完一圈后发现a[i]是其它数字的倍数返回true
// 找完一圈后发现a[i]不是其它数字的倍数则i++
//如果到了最后一个还没有找到是其它数倍数的数字那么返回false
for (int i = 1; i <= n; i++) {
bool flag = false;//默认a[i]是好用的
for (int j = 1; j <= n; j++) {
if (a[i] % a[j]) { //a[i]不是a[j]的倍数,么a[i]是个废物,后续的a[j]不用继续讨论了
flag = true;//用来标记是中间被打断的也就是不合理的a[i]
break;
}
}
//到达了这里
if (!flag)
return true;
}
return false;
}
int main() {
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (check())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}

@ -0,0 +1,7 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,77 @@
#include <bits/stdc++.h>
using namespace std;
/*
bool
int a[n];
bool xy(int n)
{
n,
int al=0;
while(n){
int t=n%10;
a[++al]=t;
n/=10;
}
a
a便
2
a[1]
1.
2.1.a[]*=7 2.if(a[]>9)
a[i]=(a[i]=a[i]%10+
a[i]/10)
int t=0;
for(int i=al;i;i--)t=t*10+a[i];
%8==0;
if(t%8==0)return true;
else return false;
}
*/
int a[100];
int ys(int n) {
while (n > 9)
n = n % 10 + n / 10;
return n;
}
bool xy(int n) {
int al = 0;
while (n) {
int t = n % 10;
a[++al] = t;
n /= 10;
}
for (int i = 1; i <= al; i++) {
if (i % 2)
a[i] = ys(a[i] * 7);
}
int t = 0;
for (int i = al; i; i--)
t = t * 10 + a[i];
return !(t % 8);
}
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
if (xy(n))
cout << "T" << endl;
else
cout << "F" << endl;
}
return 0;
}

@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;
//将一个16进制的灰阶转为一个整数方便用来当数组的下标索引值
int toDec(char a, char b) {
int res = 0;
if (a >= 'A' && a <= 'F')
res += (a - 'A' + 10) * 16;
else
res += (a - '0') * 16;
if (b >= 'A' && b <= 'F')
res += b - 'A' + 10;
else
res += b - '0';
return res;
}
//将一个十进制的灰阶值[0,255]转化成十六进制[0,FF]
string toHex(int x) {
int a = x % 16; // 0 ~ 15
int b = x / 16; //
char c1;
if (a >= 10)
c1 = 'A' + a - 10;
else
c1 = '0' + a;
char c2;
if (b >= 10)
c2 = 'A' + b - 10;
else
c2 = '0' + b;
string res;
res.push_back(c2);
res.push_back(c1);
return res;
}
int main() {
cout << toDec('A', 'B') << endl; //输出171手工计算10*16+11=171
cout << toDec('1', '2') << endl; //18
cout << toDec('0', '2') << endl; //2
cout << toHex(171) << endl;
cout << toHex(18) << endl;
cout << toHex(2) << endl;
return 0;
}

@ -0,0 +1,91 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 256;
//桶
int bucket[N];//0 ~ 255
//原始的字符串数组
string q[30];
//将一个16进制的灰阶转为一个整数方便用来当数组的下标索引值
int get(char a, char b) {
return (a - '0') * 16 + (b - '0');
}
//将一个十进制的灰阶值[0,255]转化成十六进制[0,FF]
string toHex(int x) {
string res;
int a = x % 16; // 0 ~ 15
int b = x / 16; //
if (a >= 10)
res = 'A' + a - 10;
else
res = '0' + a;
if (b >= 10)
res = res + 'A' + b - 10;
else
res = res + '0' + b;
}
//结构体,用来把桶中的灰阶按数量排序用的
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;
}
};
vector<Node> vec;//需要把bucket组装成Node放到数组p中才能使用结构体排序吧
int main() {
int n;
cin >> n;//有n行数据组成了图像
for (int i = 1; i <= n; i++) {
string s;
q[i] = s;//存入原始字符串数组
cin >> s;
for (int j = 0; j < s.size(); j += 2) {
char a = s[j], b = s[j + 1];
//比如a='A' b='B' AB
//我需要把 AB计数看看有多少个
//如果我们用数组+桶来计数的话,那个桶的内容值就是数量,下标索引应该是什么东西
//比如100就是一种淡灰色现在这个淡灰色是 AB FF
int k = get(a, b); //灰阶对应的数组位置
bucket[k]++;
}
}
//找出前16位使用频率高的灰阶
//排序,按什么排序呢?
//1、按数量数量多的在前
//2、如果数量一样多呢?桶中索引小的在前
for (int i = 0; i <= 255; i++) {
vec.push_back({i, bucket[i]});
}
sort(vec.begin(), vec.end());
//有了一个已经排好序的vector<Node>
//vec[0]~vec[15]; vec[0].id vec[0].cnt
//toHex(vec[0].id)
// AA BB CC DD
for (int i = 1; i <= n; i++) { //枚举每个原始字符串每2个一组判断这个小串应该与尺子数组中的哪一个更接近
for (int j = 0; j < q[0].size(); j += 2) {
char a = q[j], b = q[j + 1]; //0 F ,0 F
//计算ab组装出的短串与上面vec中的前16个哪个距离最短
int x = get(a, b);
int mi = INT_MAX;
int mi_p = 0;
for (int k = 0; k < min(16, vec.size()); k++) { //16是有风险的因为可能没有16个那么多
if (mi > abs(vec[k] - x)) {
mi = abs(vec[k] - x);
mi_p = k;
}
}
//mi_p [0,255] -> 十六进制
//将当前的a,b这个值修改为mi_p这个灰阶值
cout << toHex(mi_p);
}
}
return 0;
}

@ -0,0 +1,114 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 256;
//桶
int b[N];//0 ~ 255
//将一个16进制的灰阶转为一个整数方便用来当数组的下标索引值
int toDec(char a, char b) {
int res = 0;
if (a >= 'A' && a <= 'F')
res += (a - 'A' + 10) * 16;
else
res += (a - '0') * 16;
if (b >= 'A' && b <= 'F')
res += b - 'A' + 10;
else
res += b - '0';
return res;
}
//将一个十进制的灰阶值[0,255]转化成十六进制[0,FF]
string toHex(int x) {
int a = x % 16; // 0 ~ 15
int b = x / 16; //
char c1;
if (a >= 10)
c1 = 'A' + a - 10;
else
c1 = '0' + a;
char c2;
if (b >= 10)
c2 = 'A' + b - 10;
else
c2 = '0' + b;
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;
}
};
vector<Node> vec;//需要把b组装成Node放到数组p中才能使用结构体排序吧
int main() {
//将测试用例引入
freopen("D://HuiJie.txt", "r", stdin);
//freopen("D://test.txt", "w",stdout);
int n;
cin >> n;//有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 = s[j], c2 = s[j + 1];
int k = toDec(c1, c2); //灰阶对应的数组位置
b[k]++;
}
}
//找出前16位使用频率高的灰阶
//排序,按什么排序呢?
//1、按数量数量多的在前
//2、如果数量一样多呢?桶中索引小的在前
for (int i = 0; i <= 255; i++) {
if (b[i]) //数量大于0的才有意义
vec.push_back({i, b[i]});
}
//使用自定义排序方法排序
sort(vec.begin(), vec.end());
//第一问
for (int i = 0; i < min(16, (int)vec.size()); i++)
cout << toHex(vec[i].id);
cout << endl;
//第二问
for (int i = 0; i < n; i++) { //枚举每个原始字符串每2个一组判断这个小串应该与尺子数组中的哪一个更接近
for (int j = 0; j < q[0].size(); j += 2) {//长度是一样长的
char c1 = q[i][j], c2 = q[i][j + 1];
//计算ab组装出的短串与上面vec中的前16个哪个距离最短
int x = toDec(c1, c2);
int mi = INT_MAX;
int mi_p = 0;
for (int k = 0; k < min(16, (int)vec.size()); k++) { //16是有风险的因为可能没有16个那么多
if (mi > abs(vec[k].id - x)) {
mi = abs(vec[k].id - x);
mi_p = k;
}
}
//mi_p [0,255] -> 十六进制
//将当前的a,b这个值修改为mi_p这个灰阶值
cout << toHex(mi_p)[1];
}
cout << endl;
}
return 0;
}
Loading…
Cancel
Save