'commit'
This commit is contained in:
BIN
GESP/资料/CSP-J模拟赛.pdf
Normal file
BIN
GESP/资料/CSP-J模拟赛.pdf
Normal file
Binary file not shown.
BIN
GESP/资料/CSP-J模拟赛答案.xlsx
Normal file
BIN
GESP/资料/CSP-J模拟赛答案.xlsx
Normal file
Binary file not shown.
19
GESP/资料/MaoPao.cpp
Normal file
19
GESP/资料/MaoPao.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N], n;
|
||||
/*
|
||||
5
|
||||
2 3 1 4 5
|
||||
*/
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
|
||||
for (int i = 1; i < n; i++) // n-1个阶段
|
||||
for (int j = 1; j < n - i; j++)
|
||||
if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);
|
||||
|
||||
for (int i = 1; i <= n; i++) cout << a[i] << " ";
|
||||
return 0;
|
||||
}
|
||||
21
GESP/资料/New_WuHouFenTao_1.cpp
Normal file
21
GESP/资料/New_WuHouFenTao_1.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
// 5只猴子,需要多少个桃子3121
|
||||
//
|
||||
// 6只猴子,
|
||||
int main() {
|
||||
for (int i = 6;; i += 5) { // 逐个尝试有i个桃子
|
||||
int x = i; // 拷贝出来,防止错误的修改
|
||||
int j;
|
||||
for (j = 0; j < 5; j++) { // 尝试5个猴子分5回
|
||||
if ((x - 1) % 5 != 0 || x <= 1) // 扔掉一个是否能分成5份
|
||||
break; // 不符合要求
|
||||
x = (x - 1) * 4 / 5; // 分完第j+1次后剩下的桃子
|
||||
}
|
||||
if (j == 5) { // 符合条件
|
||||
printf("%d", i);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
19
GESP/资料/New_WuHouFenTao_2.cpp
Normal file
19
GESP/资料/New_WuHouFenTao_2.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int i, j;
|
||||
for (i = 6;; i += 5) {
|
||||
int x = i;
|
||||
for (j = 0; j < 5; j++) {
|
||||
if ((x - 1) % 5 != 0 || x <= 1) // 扔掉一个是否能分成5份
|
||||
break; // 不符合要求
|
||||
x = (x - 1) / 5 * 4; // 分完第j+1次后剩下的桃子
|
||||
}
|
||||
if (j == 5) { // 符合条件
|
||||
printf("%d", i);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
25
GESP/资料/New_WuHouFenTao_3.cpp
Normal file
25
GESP/资料/New_WuHouFenTao_3.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int i, j;
|
||||
// 5只猴子,需要多少个桃子3121
|
||||
// 6只猴子,需要多少个桃子46651
|
||||
// 7只猴子,需要多少个桃子823537
|
||||
// 8只猴子,需要多少个桃子16777209
|
||||
// 9只猴子,需要多少个桃子682153588
|
||||
int main() {
|
||||
int m, q;
|
||||
cin >> m >> q;
|
||||
for (i = 1;; i++) { // 逐个尝试有i个桃子
|
||||
int x = i; // 拷贝出来,防止错误的修改
|
||||
for (j = 0; j < m; j++) { // 尝试5个猴子分5回
|
||||
if ((x - q) % m != 0 || x <= q) // 扔掉一个是否能分成5份
|
||||
break; // 不符合要求
|
||||
x = (x - q) * (m - 1) / m; // 分完第j+1次后剩下的桃子
|
||||
}
|
||||
if (j == m) { // 符合条件
|
||||
printf("%d", i);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
33
GESP/资料/NoBreak.cpp
Normal file
33
GESP/资料/NoBreak.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
// C++入门经典-例3.13-不加break的switch判断语句
|
||||
// https://blog.csdn.net/lovemi93/article/details/90702825
|
||||
|
||||
int main() {
|
||||
char c;
|
||||
while (1) {
|
||||
cin >> c;
|
||||
if (c == 'q') break;
|
||||
|
||||
switch (c) {
|
||||
case 'A':
|
||||
cout << "1 ";
|
||||
break;
|
||||
case 'B':
|
||||
cout << "3 ";
|
||||
case 'C':
|
||||
cout << "3 ";
|
||||
case 'D':
|
||||
cout << "Here!";
|
||||
cout << "5 ";
|
||||
break;
|
||||
case 'E':
|
||||
cout << "5 ";
|
||||
break;
|
||||
default:
|
||||
cout << "9 " << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
31
GESP/资料/SheXingJuZhen.cpp
Normal file
31
GESP/资料/SheXingJuZhen.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int dx[] = {0, 1, 0, -1}; // 右下左上
|
||||
int dy[] = {1, 0, -1, 0}; // 右下左上
|
||||
int a[N][N];
|
||||
int x, y, p; // x,y:当前蛇走到的坐标位置;p:现在正在使用哪个方向
|
||||
int n, m;
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n * m; i++) { // 没有填充完毕
|
||||
a[x][y] = i; // 在当前位置填充数字, 值在长大
|
||||
// p是说方向数组中的游标,它是需要变化的,什么情况下变化呢?
|
||||
// 1、出界了就变化 2、遇到了障碍就变化
|
||||
int tx = x + dx[p], ty = y + dy[p]; // 蛇准备去的位置
|
||||
if (tx >= n || ty >= m || tx < 0 || ty < 0 || a[tx][ty])
|
||||
p = (p + 1) % 4; // 换下个方向(本题比较容易,因为在没有填充完时,每次碰壁只需换下个方向就一定有可以走的路)
|
||||
|
||||
// 下一个坐标位置 : 注意:下面的代码不能用 x=tx,y=ty!!! 原因是经过上面的转换,p可能变化了!!!
|
||||
x += dx[p], y += dy[p];
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++)
|
||||
printf("%3d", a[i][j]);
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
39
GESP/资料/TangDou.cpp
Normal file
39
GESP/资料/TangDou.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
string zshiliu(int u) {
|
||||
char q, p;
|
||||
string s = "";
|
||||
if (u / 16 >= 10)
|
||||
p = 'A' + u / 16 - 10;
|
||||
else
|
||||
p = '0' + u / 16;
|
||||
s += p;
|
||||
if (u % 16 >= 10)
|
||||
q = 'A' + u % 16 - 10;
|
||||
else
|
||||
q = '0' + u % 16;
|
||||
s += q;
|
||||
return s;
|
||||
}
|
||||
int zshi(string s) {
|
||||
int a = 0;
|
||||
if (s[0] >= 'A' && s[0] <= 'F')
|
||||
a = (s[0] - 'A' + 10) * 16;
|
||||
else if (s[0] >= '0' && s[0] <= '9')
|
||||
a = (s[0] - '0') * 16;
|
||||
|
||||
int b = 0;
|
||||
if (s[1] >= 'A' && s[1] <= 'F')
|
||||
b = (s[1] - 'A' + 10);
|
||||
else if (s[1] >= '0' && s[1] <= '9')
|
||||
b = (s[1] - '0');
|
||||
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cout << zshiliu(10) << endl;
|
||||
cout << zshi("FF") << endl;
|
||||
cout << zshi("AA") << endl;
|
||||
return 0;
|
||||
}
|
||||
22
GESP/资料/WuHouZiFenTao.cpp
Normal file
22
GESP/资料/WuHouZiFenTao.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <bits/stdc++.h>
|
||||
// https://blog.csdn.net/weixin_43772810/article/details/121048802
|
||||
// https://blog.csdn.net/weixin_43772810/article/details/121297946
|
||||
using namespace std;
|
||||
int main() {
|
||||
int i = 0, j = 0;
|
||||
int tmp = 0;
|
||||
for (i = 1; i <= 10000; i++) {
|
||||
tmp = i;
|
||||
for (j = 0; j < 5; j++) {
|
||||
if ((tmp - 1) % 5 != 0 || tmp <= 1)
|
||||
break;
|
||||
tmp = (tmp - 1) / 5 * 4;
|
||||
}
|
||||
if (j == 5) {
|
||||
printf("there was %d peaches.\n", i);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
printf("thats too more!");
|
||||
return 0;
|
||||
}
|
||||
37
GESP/资料/dad.cpp
Normal file
37
GESP/资料/dad.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 40;
|
||||
int n; //一个n*n的幻方
|
||||
int g[N][N]; //一个二维数组用来存储幻方
|
||||
int x, y; //用来记录上一个位置
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
//1≤N≤39 且 N 为奇数。
|
||||
|
||||
//(1)首先,将1写在第一行的中间
|
||||
g[1][n / 2 + 1] = 1; // n/2+1,是因为n是奇数噢,偶数不用+1
|
||||
|
||||
//记录上一个放置的位置【这个很重要,一定要记录上一次的位置!!!】
|
||||
x = 1;
|
||||
y = n / 2 + 1;
|
||||
|
||||
//尝试将2-n^2的数字放入 [核心思想:上一个位置]
|
||||
for (int i = 2; i <= n * n; i++) {
|
||||
if (x == 1 && y != n) g[n][y + 1] = i, x = n, y++;
|
||||
else if (y == n && x != 1) g[x - 1][1] = i, x--, y = 1;
|
||||
else if (x == 1 && y == n)g[2][n] = i, x = 2;
|
||||
else if (x != 1 && y != n) {
|
||||
if (g[x - 1][y + 1] == 0) g[x - 1][y + 1] = i, x--, y++;
|
||||
else g[x + 1][y] = i, x++;
|
||||
}
|
||||
}
|
||||
//输出
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++)
|
||||
cout << g[i][j] << " ";
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
GESP/资料/sh.cpp
Normal file
10
GESP/资料/sh.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
int main() {
|
||||
int a, b, c;
|
||||
int x;
|
||||
cin >> a >> b >> c;
|
||||
|
||||
return 0;
|
||||
}
|
||||
47
GESP/资料/sizeof.cpp
Normal file
47
GESP/资料/sizeof.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
bool issimilar(string a, string b) {
|
||||
if (abs((int)a.size() - (int)b.size()) > 1)
|
||||
return false;
|
||||
if (a.size() == b.size()) {
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
if (a[i] != b[i])
|
||||
if (cnt++ > 1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
int cnt = 0;
|
||||
if (a.size() > b.size())
|
||||
swap(a, b);
|
||||
int j = 0;
|
||||
for (int i = 0; i < a.size();) {
|
||||
if (a[i] != b[j]) {
|
||||
cnt++;
|
||||
j++;
|
||||
} else {
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (cnt > 1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int T;
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
string a, b;
|
||||
cin >> a >> b;
|
||||
if (issimilar(a, b)) {
|
||||
cout << "similar" << endl;
|
||||
} else
|
||||
cout << "not similar" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/资料/一级错题本.docx
Normal file
BIN
GESP/资料/一级错题本.docx
Normal file
Binary file not shown.
23
GESP/资料/做题.cpp
Normal file
23
GESP/资料/做题.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1e6 + 10;//<2F>ⵥ<EFBFBD><E2B5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int a[N];//ÿ<><C3BF><EFBFBD>ⵥ<EFBFBD><E2B5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
sort(a + 1, a + 1 + n);
|
||||
|
||||
int h = 1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3A3ACB4>Ƚϵ<C8BD><CFB5>ⵥ<EFBFBD><E2B5A5>
|
||||
for (int i = 1;;) { //ö<><C3B6>ÿһ<C3BF>죬<EFBFBD><ECA3AC><EFBFBD><EFBFBD>breakֹͣ
|
||||
if (a[h] >= i) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>һ<EFBFBD><D2BB>
|
||||
i++;
|
||||
if (++h > n) {
|
||||
cout << i - 1 << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
97
GESP/资料/原码反码补码.md
Normal file
97
GESP/资料/原码反码补码.md
Normal file
@@ -0,0 +1,97 @@
|
||||
首先提几个概念: 原码,反码,补码
|
||||
|
||||
### 原码是什么?
|
||||
|
||||
原码就是早期用来表示数字的一种方式: 一个正数,转换为二进制位就是这个正数的原码。负数的绝对值转换成二进制位然后在高位补1就是这个负数的原码
|
||||
|
||||
举例说明:
|
||||
|
||||
int类型的 3 的原码是 11B(B表示二进制位), 在32位机器上占四个字节,那么高位补零就得:
|
||||
|
||||
00000000 00000000 00000000 00000011
|
||||
|
||||
int类型的 -3 的绝对值的二进制位就是上面的 11B 展开后高位补零就得:
|
||||
|
||||
10000000 00000000 00000000 00000011
|
||||
|
||||
但是原码有几个缺点,零分两种 +0 和 -0 。很奇怪是吧!还有,在进行不同符号的加法运算或者同符号的减法运算的时候,不能直接判断出结果的正负。你需要将两个值的绝对值进行比较,然后进行加减操作 ,最后符号位由绝对值大的决定。于是反码就产生了。
|
||||
|
||||
|
||||
|
||||
### 反码是什么 ?
|
||||
|
||||
正数的反码就是原码,负数的反码等于原码除符号位以外所有的位取反
|
||||
|
||||
举例说明:
|
||||
|
||||
int类型的 3 的反码是
|
||||
|
||||
00000000 00000000 00000000 00000011
|
||||
|
||||
和原码一样没什么可说的
|
||||
|
||||
int类型的 -3 的反码是
|
||||
|
||||
11111111 11111111 11111111 11111100
|
||||
|
||||
除开符号位 所有位 取反
|
||||
|
||||
解决了加减运算的问题,但还是有正负零之分,然后就到补码了
|
||||
|
||||
|
||||
|
||||
### 补码是什么?
|
||||
|
||||
正数的补码与原码相同,负数的补码为 其原码除符号位外所有位取反(得到反码了),然后最低位加1.
|
||||
|
||||
还是举例说明:
|
||||
|
||||
int类型的 3 的补码是:
|
||||
|
||||
00000000 00000000 00000000 00000011
|
||||
|
||||
int类型的 -3 的补码是
|
||||
|
||||
11111111 11111111 1111111 11111101
|
||||
|
||||
就是其反码加1
|
||||
|
||||
|
||||
|
||||
最后总结一下:
|
||||
|
||||
#### ① 正数的反码和补码都与原码相同
|
||||
|
||||
#### ② 负数的反码为对该数的原码除符号位外各位取反
|
||||
|
||||
#### ③ 负数的补码为对该数的原码除符号位外各位取反,末位+1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
各自的优缺点:
|
||||
|
||||
原码最好理解了,但是加减法不够方便,还有两个零。。
|
||||
|
||||
反码稍微困难一些,解决了加减法的问题,但还是有有个零
|
||||
|
||||
补码理解困难,其他就没什么缺点了
|
||||
|
||||
喔日,说到这里,估计都晕了,举个栗子把。
|
||||
|
||||
5的原码是 00000000000000000000000000000101(四个字节,32位(byte))
|
||||
|
||||
5的原码和反码,补码都一样。
|
||||
|
||||
-5的原码是原码除符号位以外所有的位取反 ,$10000000000000000000000000000101$
|
||||
|
||||
-5的反码就是原码符合外取反得到反码
|
||||
$11111111111111111111111111111010$
|
||||
|
||||
-5的补码就是反码加一得到补码
|
||||
$11111111111111111111111111111011$
|
||||
|
||||
最后补充一句,负数一般用补码来计算。
|
||||
|
||||
|
||||
26
GESP/资料/四级.txt
Normal file
26
GESP/资料/四级.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
选择排序不是稳定的排序算法
|
||||
https://blog.csdn.net/weixin_39644325/article/details/111584150
|
||||
数组 6、7、6、2、8
|
||||
|
||||
不稳定排序算法有哪些
|
||||
https://blog.csdn.net/Maxiao1204/article/details/108907709
|
||||
|
||||
不稳定排序算法有哪些
|
||||
口诀:一堆(堆)希尔(希尔)快(快速)选(选择)
|
||||
|
||||
======================================================
|
||||
桶排不讨论是不是稳定
|
||||
桶排的例子
|
||||
|
||||
6 7 6 2 8
|
||||
|
||||
|
||||
int a[10]={};
|
||||
|
||||
1 2 1 1
|
||||
1 2 3 4 5 6 7 8
|
||||
|
||||
2 6 6 7 8
|
||||
|
||||
C++ 运算符
|
||||
https://www.runoob.com/cplusplus/cpp-operators.html
|
||||
27
GESP/资料/小猫分鱼.md
Normal file
27
GESP/资料/小猫分鱼.md
Normal file
@@ -0,0 +1,27 @@
|
||||

|
||||
|
||||
```cpp {.line-numbers}
|
||||
// Created by www.runoob.com on 15/11/9.
|
||||
// Copyright © 2015年 菜鸟教程. All rights reserved.
|
||||
//
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
int main()
|
||||
{
|
||||
int x,i=0,j=1;
|
||||
while(i<5){
|
||||
x=4*j;
|
||||
for(i=0;i<5;i++)
|
||||
{
|
||||
if(x%4!=0){break;}
|
||||
x=(x/4)*5+1;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
printf("%d\n",x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
77
GESP/资料/幸运数.cpp
Normal file
77
GESP/资料/幸运数.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
/*
|
||||
<09><><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD>Ҫ¼<D2AA><C2BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>
|
||||
Ҫbool<6F><6C>
|
||||
int a[n];
|
||||
bool xy(int n)Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
{<7B><><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>أ<EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>룺
|
||||
<20><>Ҫʲô<CAB2><C3B4>
|
||||
<20><>Ҫһ<D2AA><D2BB>n,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20>洢<EFBFBD><E6B4A2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int al=0;
|
||||
while(n){
|
||||
int t=n%10;
|
||||
a[++al]=t;
|
||||
n/=10;
|
||||
}
|
||||
a<><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʲô<CAB2><C3B4>
|
||||
a<><61><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>ż<EFBFBD><C5BC>λ
|
||||
<09><>ʼ<EFBFBD>жϣ<D0B6>
|
||||
ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>λΪһ<CEAA><D2BB>ʮλΪ2<CEAA><32><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
<09><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>a[1]<5D><>
|
||||
<09><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
1.ż<><C5BC>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD> ע<>⣬<EFBFBD><E2A3AC><EFBFBD>ж<EFBFBD>ż<EFBFBD><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
2.<2E><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>1.a[<5B><><EFBFBD><EFBFBD>λ]*=7 2.if(a[<5B><><EFBFBD><EFBFBD>λ]>9)
|
||||
a[i]=<3D><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>(<28>˴<EFBFBD><CBB4><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>a[i]=a[i]%10+
|
||||
a[i]/10)<29><>
|
||||
<09><>ô<EFBFBD><C3B4>Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD>
|
||||
<09><>ô<EFBFBD><C3B4><EFBFBD>أ<EFBFBD>
|
||||
int t=0;
|
||||
for(int i=al;i;i--)t=t*10+a[i];
|
||||
<09>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>%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;
|
||||
}
|
||||
123
GESP/资料/排序算法.md
Normal file
123
GESP/资料/排序算法.md
Normal file
@@ -0,0 +1,123 @@
|
||||
## 排序算法专题
|
||||
|
||||
### 一、基本知识
|
||||
有些人可能不知道什么是稳定排序、原地排序、时间复杂度、空间复杂度,我这里先简单解释一下:
|
||||
|
||||
1、稳定排序:如果 a 原本在 b 的前面,且 a == b,排序之后 a 仍然在 b 的前面,则为稳定排序
|
||||
|
||||
2、非稳定排序:如果 a 原本在 b 的前面,且 a == b,排序之后 a 可能不在 b 的前面,则为非稳定排序。
|
||||
|
||||
3、原地排序:原地排序就是指在排序过程中不申请多余的存储空间,只利用原来存储待排数据的存储 空间进行比较和交换的数据排序。
|
||||
|
||||
4、非原地排序:需要利用额外的数组来辅助排序。
|
||||
|
||||
5、时间复杂度:一个算法执行所消耗的时间。
|
||||
|
||||
6、空间复杂度:运行完一个算法所需的内存大小
|
||||
|
||||

|
||||
|
||||
#### 口诀: 快选希堆
|
||||
|
||||
### 二、快速排序
|
||||
```cpp {.line-numbers}
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 100010;
|
||||
int q[N];
|
||||
int n;
|
||||
|
||||
/**
|
||||
* 功能:利用快速排序对数组进行排序
|
||||
* @param q 要排序的数组
|
||||
* @param l 左端下标位置
|
||||
* @param r 右端下标位置
|
||||
*/
|
||||
void quick_sort(int q[], int l, int r) {
|
||||
if (l >= r) return;
|
||||
int i = l - 1, j = r + 1, x = q[(l + r) >> 1];
|
||||
while (i < j) {
|
||||
do i++;
|
||||
while (q[i] < x);
|
||||
do j--;
|
||||
while (q[j] > x);
|
||||
if (i < j) swap(q[i], q[j]);
|
||||
}
|
||||
quick_sort(q, l, j), quick_sort(q, j + 1, r);
|
||||
}
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++) scanf("%d", &q[i]);
|
||||
quick_sort(q, 1, n);
|
||||
for (int i = 1; i <= n; i++) printf("%d ", q[i]);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
### 三、归并排序
|
||||
```cpp {.line-numbers}
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e5 + 10;
|
||||
int q[N], t[N];
|
||||
|
||||
void merge_sort(int q[], int l, int r) {
|
||||
if (l >= r) return;
|
||||
|
||||
int mid = (l + r) >> 1;
|
||||
merge_sort(q, l, mid), merge_sort(q, mid + 1, r);
|
||||
|
||||
int i = l, j = mid + 1, k = 0;
|
||||
while (i <= mid && j <= r)
|
||||
if (q[i] <= q[j])
|
||||
t[k++] = q[i++];
|
||||
else
|
||||
t[k++] = q[j++];
|
||||
|
||||
while (i <= mid) t[k++] = q[i++];
|
||||
while (j <= r) t[k++] = q[j++];
|
||||
for (i = l, j = 0; i <= r; i++, j++) q[i] = t[j];
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> q[i];
|
||||
|
||||
merge_sort(q, 1, n);
|
||||
for (int i = 1; i <= n; i++) printf("%d ", q[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
### 四、结构体自定义排序
|
||||
```cpp {.line-numbers}
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
// 学生的结构体
|
||||
struct Node {
|
||||
string name;
|
||||
int math;
|
||||
int english;
|
||||
};
|
||||
|
||||
// 函数实现
|
||||
bool cmp(Node &a, Node &b) {
|
||||
if (a.math == b.math)
|
||||
return a.english > b.english; // math相等,按endlish从大到小排序23
|
||||
return a.math > b.math; // 按math从大到小排序
|
||||
}
|
||||
|
||||
int main() {
|
||||
// 先按math从大到小排序,math相等,按english从大到小排序
|
||||
Node a[4] = {{"XiaoMing", 67, 89}, {"LiLei", 90, 56}, {"ZhaoSi", 90, 99}};
|
||||
sort(a, a + 3, cmp);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
cout << a[i].name << " " << a[i].math << " " << a[i].english << endl;
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
1
GESP/资料/灰阶图像/1.txt
Normal file
1
GESP/资料/灰阶图像/1.txt
Normal file
@@ -0,0 +1 @@
|
||||
AAAA6AAAA6
|
||||
48
GESP/资料/灰阶图像/十六进制转换测试.cpp
Normal file
48
GESP/资料/灰阶图像/十六进制转换测试.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
int toDec(char a, char b) {
|
||||
int res = 0;
|
||||
if (a >= '0' && a <= '9')
|
||||
res += (a - '0') * 16;
|
||||
else if (a >= 'A' && a <= 'F')
|
||||
res += (a - 'A' + 10) * 16;
|
||||
|
||||
if (b >= '0' && b <= '9')
|
||||
res += b - '0';
|
||||
else if (b >= 'A' && b <= 'F')
|
||||
res += b - 'A' + 10;
|
||||
return res;
|
||||
}
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[0,FF]
|
||||
string toHex(int x) {
|
||||
char c1, c2;
|
||||
int a = x % 16; // 0 ~ 15
|
||||
int b = x / 16; //
|
||||
if (a >= 10)
|
||||
c1 = 'A' + a - 10;
|
||||
else
|
||||
c1 = '0' + a;
|
||||
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;// AB-->? 10*16+ 11 =171
|
||||
cout << toDec('1', '3') << endl;// 19
|
||||
cout << toDec('1', 'A') << endl;// 26
|
||||
|
||||
cout << toHex(171) << endl; //AB
|
||||
cout << toHex(19) << endl; //13
|
||||
cout << toHex(26) << endl; //1A
|
||||
return 0;
|
||||
}
|
||||
50
GESP/资料/灰阶图像/十进制与十六进制互转.cpp
Normal file
50
GESP/资料/灰阶图像/十进制与十六进制互转.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
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;
|
||||
}
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>171<37><31><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>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;
|
||||
}
|
||||
114
GESP/资料/灰阶图像/新文件1.cpp
Normal file
114
GESP/资料/灰阶图像/新文件1.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#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<64>ٵ<EFBFBD><D9B5>ˣ<EFBFBD><CBA3>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>
|
||||
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]++;
|
||||
}
|
||||
}
|
||||
// ѡ<>ٿ<EFBFBD>ʼ~~~
|
||||
// <20><><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǻܶ<C7BA><DCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>256<35><36>Ҳ<EFBFBD><D2B2><EFBFBD>ܸ<EFBFBD><DCB8>٣<EFBFBD><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>֣<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>Ҫѡ<D2AA><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<31><36><EFBFBD><EFBFBD><EFBFBD>壡
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>vec<node><3E><>
|
||||
// vec<node><3E><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>for<6F><72>1<EFBFBD><31>mx<6D><78><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mx<6D><78><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>mx_id<69><64><EFBFBD><EFBFBD>ֵ<EFBFBD>ı<EFBFBD><C4B1>ţ<EFBFBD>
|
||||
//<2F><>һ<EFBFBD><D2BB>vec<int>!
|
||||
//<2F><>ʼ<EFBFBD>ɣ<EFBFBD>
|
||||
// for (int i = 0; i <= 255; i++)
|
||||
// if (b[i])
|
||||
// vec.push_back({i, b[i]});
|
||||
//Ϊ<>˷<EFBFBD>ֹ<EFBFBD><D6B9>ɫ<EFBFBD><C9AB>ð<EFBFBD>䣬<EFBFBD><E4A3AC>ɸһ<C9B8>飬Ȼ<E9A3AC><C8BB>¼<EFBFBD><C2BC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// sort(vec.begin(), vec.end());
|
||||
//<2F>ɴ<EFBFBD><C9B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʮ<C7B0><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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;
|
||||
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>~<7E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
for (int i = 1; i <= 16; i++)
|
||||
cout << toHex(vec[i]);
|
||||
cout << endl;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>~
|
||||
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;
|
||||
}
|
||||
87
GESP/资料/灰阶图像/无noid版本1.cpp
Normal file
87
GESP/资料/灰阶图像/无noid版本1.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#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 - 'A' + 10) * 16;
|
||||
else
|
||||
res += (a - '0') * 16;
|
||||
if (b >= 'A' && b <= 'F')
|
||||
res += b - 'A' + 10;
|
||||
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;
|
||||
|
||||
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 = s[j], c2 = s[j + 1];
|
||||
int k = toDec(c1, c2);
|
||||
b[k]++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int 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);
|
||||
|
||||
b[mx_id] = -1;
|
||||
}
|
||||
for (int i = 0; i < min(16, (int)vec.size()); i++)
|
||||
cout << toHex(vec[i]) ;
|
||||
cout << endl;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < q[0].size(); j += 2) {
|
||||
int 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 < min(16, (int)vec.size()); k++) {
|
||||
if (mi > abs(vec[k] - x)) {
|
||||
mi = abs(vec[k] - x);
|
||||
mi_p = k;
|
||||
}
|
||||
}
|
||||
cout << toHex(mi_p)[1];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
91
GESP/资料/灰阶图像/灰阶图像 - 第一个版本.cpp
Normal file
91
GESP/资料/灰阶图像/灰阶图像 - 第一个版本.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 256;
|
||||
//Ͱ
|
||||
int bucket[N];//0 ~ 255
|
||||
|
||||
//ԭʼ<D4AD><CABC><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
string q[30];
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
int get(char a, char b) {
|
||||
return (a - '0') * 16 + (b - '0');
|
||||
}
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[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;
|
||||
}
|
||||
|
||||
//<2F>ṹ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>еĻҽװ<D2BD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>
|
||||
struct Node {
|
||||
int id;//<2F><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
|
||||
int cnt;//<2F><><EFBFBD><EFBFBD>
|
||||
const bool operator<(const Node &b) const {
|
||||
if (cnt == b.cnt)
|
||||
return id < b.id;
|
||||
return cnt > b.cnt;
|
||||
}
|
||||
};
|
||||
vector<Node> vec;//<2F><>Ҫ<EFBFBD><D2AA>bucket<65><74>װ<EFBFBD><D7B0>Node<64>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ýṹ<C3BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;//<2F><>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
q[i] = s;//<2F><><EFBFBD><EFBFBD>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
cin >> s;
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char a = s[j], b = s[j + 1];
|
||||
//<2F><><EFBFBD><EFBFBD>a='A' b='B' AB
|
||||
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA> AB<41><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ٸ<EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+Ͱ<><CDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>Ǹ<EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>100<30><30><EFBFBD><EFBFBD>һ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB> AB FF
|
||||
int k = get(a, b); //<2F>ҽ<D2BD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
bucket[k]++;
|
||||
}
|
||||
}
|
||||
//<2F>ҳ<EFBFBD>ǰ16λʹ<CEBB><CAB9>Ƶ<EFBFBD>ʸߵĻҽ<C4BB>
|
||||
//<2F><><EFBFBD><EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
|
||||
//1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ
|
||||
//2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?Ͱ<><CDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ǰ
|
||||
for (int i = 0; i <= 255; i++) {
|
||||
vec.push_back({i, bucket[i]});
|
||||
}
|
||||
sort(vec.begin(), vec.end());
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ѿ<EFBFBD><D1BE>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>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++) { //ö<><C3B6>ÿ<EFBFBD><C3BF>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ÿ2<C3BF><32>һ<EFBFBD>飬<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
|
||||
for (int j = 0; j < q[0].size(); j += 2) {
|
||||
char a = q[j], b = q[j + 1]; //0 F ,0 F
|
||||
//<2F><><EFBFBD><EFBFBD>ab<61><62>װ<EFBFBD><D7B0><EFBFBD>Ķ̴<C4B6><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>vec<65>е<EFBFBD>ǰ16<31><36><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int x = get(a, b);
|
||||
int mi = INT_MAX;
|
||||
int mi_p = 0;
|
||||
for (int k = 0; k < min(16, vec.size()); k++) { //16<31><36><EFBFBD>з<EFBFBD><D0B7>յģ<D5B5><C4A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>û<EFBFBD><C3BB>16<31><36><EFBFBD><EFBFBD>ô<EFBFBD><C3B4>
|
||||
if (mi > abs(vec[k] - x)) {
|
||||
mi = abs(vec[k] - x);
|
||||
mi_p = k;
|
||||
}
|
||||
}
|
||||
//mi_p [0,255] -> ʮ<><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>a,b<><62><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Ϊmi_p<5F><70><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD>ֵ
|
||||
cout << toHex(mi_p);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
121
GESP/资料/灰阶图像/灰阶图像.cpp
Normal file
121
GESP/资料/灰阶图像/灰阶图像.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 256;
|
||||
//Ͱ
|
||||
int b[N];//0 ~ 255
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
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;
|
||||
}
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[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;
|
||||
}
|
||||
|
||||
|
||||
//ԭʼ<D4AD><CABC><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
vector<string> q;
|
||||
|
||||
//<2F>ṹ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>еĻҽװ<D2BD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>
|
||||
struct Node {
|
||||
int id;//<2F><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
|
||||
int cnt;//<2F><><EFBFBD><EFBFBD>
|
||||
const bool operator<(const Node &b) const {
|
||||
if (cnt == b.cnt)
|
||||
return id < b.id;
|
||||
return cnt > b.cnt;
|
||||
}
|
||||
};
|
||||
vector<Node> vec;//<2F><>Ҫ<EFBFBD><D2AA>b<EFBFBD><62>װ<EFBFBD><D7B0>Node<64>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ýṹ<C3BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
int main() {
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
freopen("D://HuiJie.txt", "r", stdin);
|
||||
//freopen("D://test.txt", "w",stdout);
|
||||
|
||||
int n;
|
||||
cin >> n;//<2F><>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
cin >> s;
|
||||
q.push_back(s);//ԭʼ<D4AD><CABC><EFBFBD><EFBFBD>
|
||||
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char c1 = s[j], c2 = s[j + 1];
|
||||
int k = toDec(c1, c2); //<2F>ҽ<D2BD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
b[k]++;
|
||||
}
|
||||
}
|
||||
//<2F>ҳ<EFBFBD>ǰ16λʹ<CEBB><CAB9>Ƶ<EFBFBD>ʸߵĻҽ<C4BB>
|
||||
//<2F><><EFBFBD><EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
|
||||
//1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ
|
||||
//2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?Ͱ<><CDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ǰ
|
||||
for (int i = 0; i <= 255; i++) {
|
||||
if (b[i]) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
vec.push_back({i, b[i]});
|
||||
}
|
||||
//ʹ<><CAB9><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B7BDB7><EFBFBD><EFBFBD><EFBFBD>
|
||||
sort(vec.begin(), vec.end());
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>
|
||||
for (int i = 0; i < min(16, (int)vec.size()); i++)
|
||||
cout << toHex(vec[i].id);
|
||||
cout << endl;
|
||||
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
for (int i = 0; i < n; i++) { //ö<><C3B6>ÿ<EFBFBD><C3BF>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ÿ2<C3BF><32>һ<EFBFBD>飬<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
|
||||
for (int j = 0; j < q[0].size(); j += 2) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char c1 = q[i][j], c2 = q[i][j + 1];
|
||||
//<2F><><EFBFBD><EFBFBD>ab<61><62>װ<EFBFBD><D7B0><EFBFBD>Ķ̴<C4B6><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>vec<65>е<EFBFBD>ǰ16<31><36><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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<31><36><EFBFBD>з<EFBFBD><D0B7>յģ<D5B5><C4A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>û<EFBFBD><C3BB>16<31><36><EFBFBD><EFBFBD>ô<EFBFBD><C3B4>
|
||||
if (mi > abs(vec[k].id - x)) {
|
||||
mi = abs(vec[k].id - x);
|
||||
mi_p = k;
|
||||
}
|
||||
}
|
||||
//mi_p [0,255] -> ʮ<><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>a,b<><62><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Ϊmi_p<5F><70><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD>ֵ
|
||||
cout << toHex(mi_p)[1];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
102
GESP/资料/灰阶图像/糖豆版本 2.cpp
Normal file
102
GESP/资料/灰阶图像/糖豆版本 2.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
int toDec(char a, char b) {
|
||||
int res = 0;
|
||||
if (a >= '0' && a <= '9')
|
||||
res += (a - '0') * 16;
|
||||
else if (a >= 'A' && a <= 'F')
|
||||
res += (a - 'A' + 10) * 16;
|
||||
|
||||
if (b >= '0' && b <= '9')
|
||||
res += b - '0';
|
||||
else if (b >= 'A' && b <= 'F')
|
||||
res += b - 'A' + 10;
|
||||
return res;
|
||||
}
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[0,FF]
|
||||
string toHex(int x) {
|
||||
char c1, c2;
|
||||
int a = x % 16; // 0 ~ 15
|
||||
int b = x / 16; //
|
||||
if (a >= 10)
|
||||
c1 = 'A' + a - 10;
|
||||
else
|
||||
c1 = '0' + a;
|
||||
if (b >= 10)
|
||||
c2 = 'A' + b - 10;
|
||||
else
|
||||
c2 = '0' + b;
|
||||
|
||||
string res;
|
||||
res.push_back(c2);
|
||||
res.push_back(c1);
|
||||
return res;
|
||||
}
|
||||
|
||||
const int N = 256;
|
||||
//Ͱ
|
||||
int bucket[N];//0 ~ 255
|
||||
|
||||
//ԭʼ<D4AD><CABC><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
string q[30];
|
||||
|
||||
//<2F>ṹ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>еĻҽװ<D2BD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>
|
||||
struct Node {
|
||||
int id;//<2F><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
|
||||
int cnt;//<2F><><EFBFBD><EFBFBD>
|
||||
const bool operator<(const Node &b) const {
|
||||
if (cnt == b.cnt)
|
||||
return id < b.id;
|
||||
return cnt > b.cnt;
|
||||
}
|
||||
};
|
||||
vector<Node> vec;//<2F><>Ҫ<EFBFBD><D2AA>bucket<65><74>װ<EFBFBD><D7B0>Node<64>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ýṹ<C3BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
int main() {
|
||||
freopen("D://HuiJie.txt", "r", stdin);
|
||||
|
||||
int n;
|
||||
cin >> n;//<2F><>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
cin >> s;
|
||||
q[i] = s;//<2F><><EFBFBD><EFBFBD>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char a = s[j], b = s[j + 1];
|
||||
int k = toDec(a, b); //<2F>ҽ<D2BD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
bucket[k]++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 255; i++)
|
||||
vec.push_back({i, bucket[i]});
|
||||
sort(vec.begin(), vec.end());
|
||||
|
||||
//ǰʮ<C7B0><CAAE>λ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
for (int i = 0; i < min(16, (int)vec.size()); i++)
|
||||
cout << toHex(vec[i].id) ;
|
||||
cout << endl;
|
||||
|
||||
//<2F>ڶ<EFBFBD><DAB6>ʵĻش<C4BB>
|
||||
for (int i = 1; i <= n; i++) { //ö<><C3B6>ÿ<EFBFBD><C3BF>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ÿ2<C3BF><32>һ<EFBFBD>飬<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
|
||||
for (int j = 0; j < q[1].size(); j += 2) {
|
||||
char a = q[i][j], b = q[i][j + 1]; //0 F ,0 F
|
||||
int x = toDec(a, b);
|
||||
int mi = INT_MAX;
|
||||
int mi_p = 0;
|
||||
for (int k = 0; k < min(16, (int)vec.size()); k++) { //16<31><36><EFBFBD>з<EFBFBD><D0B7>յģ<D5B5><C4A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>û<EFBFBD><C3BB>16<31><36><EFBFBD><EFBFBD>ô<EFBFBD><C3B4>
|
||||
if (mi > abs(vec[k].id - x)) {
|
||||
mi = abs(vec[k].id - x);
|
||||
mi_p = k;
|
||||
}
|
||||
}
|
||||
cout << toHex(mi_p)[1];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
102
GESP/资料/灰阶图像/糖豆版本.cpp
Normal file
102
GESP/资料/灰阶图像/糖豆版本.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
int toDec(char a, char b) {
|
||||
int res = 0;
|
||||
if (a >= '0' && a <= '9')
|
||||
res += (a - '0') * 16;
|
||||
else if (a >= 'A' && a <= 'F')
|
||||
res += (a - 'A' + 10) * 16;
|
||||
|
||||
if (b >= '0' && b <= '9')
|
||||
res += b - '0';
|
||||
else if (b >= 'A' && b <= 'F')
|
||||
res += b - 'A' + 10;
|
||||
return res;
|
||||
}
|
||||
|
||||
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[0,FF]
|
||||
string toHex(int x) {
|
||||
char c1, c2;
|
||||
int a = x % 16; // 0 ~ 15
|
||||
int b = x / 16; //
|
||||
if (a >= 10)
|
||||
c1 = 'A' + a - 10;
|
||||
else
|
||||
c1 = '0' + a;
|
||||
if (b >= 10)
|
||||
c2 = 'A' + b - 10;
|
||||
else
|
||||
c2 = '0' + b;
|
||||
|
||||
string res;
|
||||
res.push_back(c2);
|
||||
res.push_back(c1);
|
||||
return res;
|
||||
}
|
||||
|
||||
const int N = 256;
|
||||
//Ͱ
|
||||
int bucket[N];//0 ~ 255
|
||||
|
||||
//ԭʼ<D4AD><CABC><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
string q[30];
|
||||
|
||||
//<2F>ṹ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>еĻҽװ<D2BD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>
|
||||
struct Node {
|
||||
int id;//<2F><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
|
||||
int cnt;//<2F><><EFBFBD><EFBFBD>
|
||||
const bool operator<(const Node &b) const {
|
||||
if (cnt == b.cnt)
|
||||
return id < b.id;
|
||||
return cnt > b.cnt;
|
||||
}
|
||||
};
|
||||
vector<Node> vec;//<2F><>Ҫ<EFBFBD><D2AA>bucket<65><74>װ<EFBFBD><D7B0>Node<64>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ýṹ<C3BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
int main() {
|
||||
freopen("D://HuiJie.txt", "r", stdin);
|
||||
|
||||
int n;
|
||||
cin >> n;//<2F><>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
cin >> s;
|
||||
q[i] = s;//<2F><><EFBFBD><EFBFBD>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char a = s[j], b = s[j + 1];
|
||||
int k = toDec(a, b); //<2F>ҽ<D2BD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
bucket[k]++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 255; i++)
|
||||
vec.push_back({i, bucket[i]});
|
||||
sort(vec.begin(), vec.end());
|
||||
|
||||
//ǰʮ<C7B0><CAAE>λ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
for (int i = 0; i < min(16, (int)vec.size()); i++)
|
||||
cout << toHex(vec[i].id) ;
|
||||
cout << endl;
|
||||
|
||||
//<2F>ڶ<EFBFBD><DAB6>ʵĻش<C4BB>
|
||||
for (int i = 1; i <= n; i++) { //ö<><C3B6>ÿ<EFBFBD><C3BF>ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ÿ2<C3BF><32>һ<EFBFBD>飬<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
|
||||
for (int j = 0; j < q[1].size(); j += 2) {
|
||||
char a = q[i][j], b = q[i][j + 1]; //0 F ,0 F
|
||||
int x = toDec(a, b);
|
||||
int mi = INT_MAX;
|
||||
int mi_p = 0;
|
||||
for (int k = 0; k < min(16, (int)vec.size()); k++) { //16<31><36><EFBFBD>з<EFBFBD><D0B7>յģ<D5B5><C4A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>û<EFBFBD><C3BB>16<31><36><EFBFBD><EFBFBD>ô<EFBFBD><C3B4>
|
||||
if (mi > abs(vec[k].id - x)) {
|
||||
mi = abs(vec[k].id - x);
|
||||
mi_p = k;
|
||||
}
|
||||
}
|
||||
cout << toHex(mi_p)[1];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
17
GESP/资料/灰阶图像/输出文件大小.cpp
Normal file
17
GESP/资料/灰阶图像/输出文件大小.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ofstream fout;
|
||||
fout.open("1.txt");
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
if (i % 5 == 0) {
|
||||
int x = 6;
|
||||
fout << x;
|
||||
} else {
|
||||
char ch = 'A';
|
||||
fout << ch;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
35
GESP/资料/穷举法.md
Normal file
35
GESP/资料/穷举法.md
Normal file
@@ -0,0 +1,35 @@
|
||||
### 穷举法
|
||||
穷举法的基本思想是根据题目的部分条件确定答案的大致范围,并在此范围内对所有可能的情况逐一验证,直到全部情况验证完毕。若某个情况验证符合题目的全部条件,则为本问题的一个解;若全部情况验证后都不符合题目的全部条件,则本题无解。穷举法也称为枚举法。
|
||||
|
||||
用穷举法解题时,就是按照某种方式列举问题答案的过程。针对问题的数据类型而言,常用的列举方法一有如下三种:
|
||||
|
||||
(1)顺序列举 是指答案范围内的各种情况很容易与自然数对应甚至就是自然数,可以按自然数的变化顺序去列举。
|
||||
|
||||
(2)排列列举 有时答案的数据形式是一组数的排列,列举出所有答案所在范围内的排列,为排列列举。
|
||||
|
||||
(3)组合列举 当答案的数据形式为一些元素的组合时,往往需要用组合列举。组合是无序的。
|
||||
|
||||
例子如下:在公元五世纪我国数学家张丘建在其《算经》一书中提出了“百鸡问题 ”:
|
||||
“鸡翁一值钱5,鸡母一值钱3,鸡雏三值钱1。百钱买百鸡,问鸡翁、母、雏各几何?”这个数学问题的数学方程可列出如下:
|
||||
```cpp {.line-numbers}
|
||||
Cock+Hen+Chick=100
|
||||
Cock*5+Hen*3+Chick/3=100
|
||||
```
|
||||
显然这是个不定方程,适用于穷举法求解。依次取Cock值域中的一个值,然后求其他两个数,满足条件就是解。
|
||||
该问题的C语言程序算法如下:
|
||||
```cpp {.line-numbers}
|
||||
int Cock,Hen,Chick; /*定义公鸡,母鸡,鸡雏三个变量*/
|
||||
Cock=0;
|
||||
while (Cock<=19) /*公鸡最多不可能大于19*/
|
||||
{
|
||||
Hen=0;
|
||||
while (Hen<=33) /*母鸡最多不可能大于33*/
|
||||
{
|
||||
Chick=100-Cock-Hen;
|
||||
if (Cock*15+Hen*9+Chick==300)/*为了方便,将数量放大三倍比较*/
|
||||
printf("\n公鸡=%d\n母鸡=%d\n雏鸡=%d",Cock,Hen,Chick);
|
||||
Hen=Hen+1;
|
||||
}
|
||||
Cock=Cock+1;
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user