课评: 转出学生归档(王子墨/张立坤/黄俊博)+ 周四班级总结 + 新生章梓皓档案 + C++示例代码

This commit is contained in:
chengzi
2026-09-29 22:43:54 +08:00
parent 6f57dfe67e
commit 73cce4c4f5
116 changed files with 6817 additions and 248 deletions

View 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)
// 稳定的排序算法

Binary file not shown.

View 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;
}

Binary file not shown.

View 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;
}

Binary file not shown.

View 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;
}

Binary file not shown.