课评: 转出学生归档(王子墨/张立坤/黄俊博)+ 周四班级总结 + 新生章梓皓档案 + C++示例代码
This commit is contained in:
52
C++代码/CSP04/02-简单排序/冒泡排序.cpp
Normal file
52
C++代码/CSP04/02-简单排序/冒泡排序.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
void print(){
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void bubbleSort(){
|
||||
for(int i = 1; i <= n - 1; i++){ // i表示趟数
|
||||
bool ok = true; // 没有进行交换过
|
||||
for(int j = 1; j <= n - i; j++){ // 要比较的这个数的下标
|
||||
if(arr[j] > arr[j+1]){
|
||||
swap(arr[j], arr[j+1]);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if(ok){
|
||||
break;
|
||||
}
|
||||
cout << "第" << i << "趟:";
|
||||
print();
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
bubbleSort();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 时间复杂度
|
||||
// O(n*n) 最好时间复杂度 O(n) 最差时间复杂度O(n*n)
|
||||
// 稳定的排序算法
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/冒泡排序.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/冒泡排序.exe
Normal file
Binary file not shown.
42
C++代码/CSP04/02-简单排序/未命名1.cpp
Normal file
42
C++代码/CSP04/02-简单排序/未命名1.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
// 冒泡排序
|
||||
for(int i = 1; i <= n - 1; i++) { // i表示的是趟数
|
||||
bool ok = true; // 一开始我认为没有交换
|
||||
for(int j = 1; j <= n - i; j++) { // j表示的是食指 j+1
|
||||
if(arr[j] > arr[j+1]) {
|
||||
swap(arr[j], arr[j+1]);
|
||||
ok = false; // 交换过了
|
||||
}
|
||||
}
|
||||
|
||||
cout << "第" << i << "趟:";
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
|
||||
if(ok) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "最终:";
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/未命名1.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/未命名1.exe
Normal file
Binary file not shown.
22
C++代码/CSP04/02-简单排序/未命名2.cpp
Normal file
22
C++代码/CSP04/02-简单排序/未命名2.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
|
||||
int cnt = 0;
|
||||
int curr = 1;
|
||||
|
||||
for(int i = 2; i <= n; i++){
|
||||
// 第i格有多少米
|
||||
curr = curr * 2;
|
||||
cnt += curr;
|
||||
}
|
||||
|
||||
cout << cnt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/未命名2.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/未命名2.exe
Normal file
Binary file not shown.
44
C++代码/CSP04/02-简单排序/选择排序.cpp
Normal file
44
C++代码/CSP04/02-简单排序/选择排序.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
void print(){
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void selectionSort(){
|
||||
for(int i = 1; i <= n - 1; i++){ // i表示要交换的这个位置
|
||||
int maxx = arr[i]; // minn是当前的最小值
|
||||
int idx = i;
|
||||
|
||||
// 找到当前这一轮的最小值
|
||||
for(int j = i + 1; j <= n; j++){
|
||||
if(arr[j] > maxx) {
|
||||
maxx = arr[j];
|
||||
idx = j;
|
||||
}
|
||||
}
|
||||
swap(arr[i], arr[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
// 时间复杂度 O(n*n)
|
||||
// 不稳定
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
selectionSort();
|
||||
print();
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/选择排序.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/选择排序.exe
Normal file
Binary file not shown.
28
C++代码/CSP04/03-二维数组/01矩阵原样输出.cpp
Normal file
28
C++代码/CSP04/03-二维数组/01矩阵原样输出.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100][100100];
|
||||
|
||||
int main(){
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cout << arr[i][j];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
35
C++代码/CSP04/03-二维数组/图像相似度.cpp
Normal file
35
C++代码/CSP04/03-二维数组/图像相似度.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[110][110];
|
||||
int b[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> b[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
if(a[i][j] == b[i][j]){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << fixed << setprecision(2);
|
||||
cout << 100.0 * cnt / (n * m) ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/图像相似度.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/图像相似度.exe
Normal file
Binary file not shown.
33
C++代码/CSP04/03-二维数组/未命名1.cpp
Normal file
33
C++代码/CSP04/03-二维数组/未命名1.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m, num, cnt = 0;
|
||||
int arr[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
// 第一幅图
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
// 第二幅图
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
// arr[i][j]
|
||||
cin >> num;
|
||||
if(num == arr[i][j]){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 相同的像素块有cnt个 总数 n * m 相同的像素块 / 总数
|
||||
// int z = n * m;
|
||||
cout << fixed << setprecision(2) << 100.0 * cnt / (n * m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/未命名1.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/未命名1.exe
Normal file
Binary file not shown.
39
C++代码/CSP04/03-二维数组/未命名4.cpp
Normal file
39
C++代码/CSP04/03-二维数组/未命名4.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int cnt = 0;
|
||||
int a[110][110];
|
||||
int b[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
// 第一幅画读入
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
// 第二幅图
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> b[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
// 对比两幅图的相同位置进行比较
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
if(a[i][j] == b[i][j]){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 相同点数 除 n * m
|
||||
cout << fixed << setprecision(2);
|
||||
cout << 100.0 * cnt / (n * m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/未命名4.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/未命名4.exe
Normal file
Binary file not shown.
20
C++代码/CSP04/03-二维数组/未命名5.cpp
Normal file
20
C++代码/CSP04/03-二维数组/未命名5.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int age;
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){ // 第i行的所有数据
|
||||
int maxx = 0;
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> age;
|
||||
maxx = max(age, maxx);
|
||||
}
|
||||
cout << maxx << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
22
C++代码/CSP04/03-二维数组/每个小组的最大年龄.cpp
Normal file
22
C++代码/CSP04/03-二维数组/每个小组的最大年龄.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m, age;
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
int maxx = 0;
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> age;
|
||||
maxx = max(maxx, age);
|
||||
}
|
||||
cout << maxx << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/每个小组的最大年龄.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/每个小组的最大年龄.exe
Normal file
Binary file not shown.
26
C++代码/CSP04/03-二维数组/每列最大值.cpp
Normal file
26
C++代码/CSP04/03-二维数组/每列最大值.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 1; j <= m; j++){
|
||||
int maxx = 0;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
maxx = max(maxx, a[i][j]);
|
||||
}
|
||||
cout << maxx << " ";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/每列最大值.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/每列最大值.exe
Normal file
Binary file not shown.
34
C++代码/CSP04/03-二维数组/矩阵加法.cpp
Normal file
34
C++代码/CSP04/03-二维数组/矩阵加法.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[110][110];
|
||||
int b[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> b[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
a[i][j] += b[i][j];
|
||||
cout << a[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/矩阵加法.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/矩阵加法.exe
Normal file
Binary file not shown.
28
C++代码/CSP04/03-二维数组/矩阵原样输出.cpp
Normal file
28
C++代码/CSP04/03-二维数组/矩阵原样输出.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[110][110];
|
||||
|
||||
int main(){
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cout << arr[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/矩阵原样输出.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/矩阵原样输出.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user