补全9月11日至13日课评:为13名学生创建请假文档,为5个班级创建总结文档
This commit is contained in:
36
C++代码/CSP04/01/小杨有序去重.cpp
Normal file
36
C++代码/CSP04/01/小杨有序去重.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 100010;
|
||||
int n;
|
||||
int arr[MAXN];
|
||||
|
||||
int main(){
|
||||
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
if(n == 0){
|
||||
cout << endl << 0 << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int j = 1; // 慢指针
|
||||
for(int i = 2; i <= n; i++){
|
||||
// i表示快指针,一直向后移动
|
||||
if(arr[i] == arr[j]) continue;
|
||||
// 如果不相同
|
||||
arr[j+1] = arr[i];
|
||||
j++;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= j; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl << j;
|
||||
return 0;
|
||||
}
|
||||
|
||||
44
C++代码/CSP04/01/小杨的回文串.cpp
Normal file
44
C++代码/CSP04/01/小杨的回文串.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s;
|
||||
int cnt1, cnt2; // cnt1大写 cnt2小写
|
||||
|
||||
int main(){
|
||||
cin >> s;
|
||||
|
||||
int len = s.size();
|
||||
for(int i = 0; i < len; i++){
|
||||
// 先数小写的个数
|
||||
if(islower(s[i])){
|
||||
cnt2++;
|
||||
}
|
||||
// 再数大写的个数
|
||||
if(isupper(s[i])){
|
||||
cnt1++;
|
||||
// 转换成小写
|
||||
s[i] = s[i] + 32;
|
||||
}
|
||||
}
|
||||
|
||||
int l = 0, r = len - 1;
|
||||
bool ok = true;
|
||||
while(l <= r){
|
||||
if(s[l] != s[r]){
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
l++, r--;
|
||||
}
|
||||
|
||||
if(ok){
|
||||
cout << "Yes";
|
||||
} else {
|
||||
cout << "No";
|
||||
}
|
||||
|
||||
cout << endl << cnt1 << endl << cnt2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
40
C++代码/CSP04/01/小杨的幸运数字.cpp
Normal file
40
C++代码/CSP04/01/小杨的幸运数字.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, num, cnt = 0, sum = 0;
|
||||
string str = "01";
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> num;
|
||||
int t = num;
|
||||
|
||||
string out = "";
|
||||
int cnt1 = 0;// 判断1的个数
|
||||
|
||||
while(t > 0) {
|
||||
int g = t % 2;
|
||||
|
||||
if(g == 1){
|
||||
sum++; // 总数加一
|
||||
cnt1++; // 个数加一
|
||||
}
|
||||
|
||||
out = str[g] + out;
|
||||
t /= 2;
|
||||
}
|
||||
|
||||
if(cnt1 == 1){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << cnt << endl << sum;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
C++代码/CSP04/01/小杨的报数游戏.cpp
Normal file
31
C++代码/CSP04/01/小杨的报数游戏.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
int arr[110] = {0}; // 0表示当前这个同学还在,1表示这个同学出列了
|
||||
int idx = 1; // 表示当前这个叫到第几个同学
|
||||
int cnt = 0; // 本轮报数的计数器
|
||||
int p = n; // 当前人数
|
||||
|
||||
while(p != 0){
|
||||
// 先判断当前这个人是不是出列了
|
||||
if(arr[idx] == 0){
|
||||
cnt++;
|
||||
if(cnt == k){
|
||||
// 这个人出列
|
||||
cout << idx << " "; // 当前这个人出列
|
||||
arr[idx] = 1; // 修改当前这个人出列状态
|
||||
p--;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
if(idx > n){
|
||||
idx = 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
37
C++代码/CSP04/01/小杨的进制数位.cpp
Normal file
37
C++代码/CSP04/01/小杨的进制数位.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int num, k;
|
||||
string out;
|
||||
string S = "0123456789ABCDEF";
|
||||
int cnt1 = 0,cnt2 = 0;
|
||||
|
||||
int main(){
|
||||
cin >> num >> k;
|
||||
|
||||
if(num == 0){
|
||||
cout << 0 << endl << 1 << endl << 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int t = num;
|
||||
while(t > 0){
|
||||
int g = t % k;
|
||||
|
||||
out = S[g] + out;
|
||||
|
||||
t /= k;
|
||||
}
|
||||
|
||||
for(char c : out){
|
||||
if(isupper(c)){
|
||||
cnt2++;
|
||||
}else if(isdigit(c)){
|
||||
cnt1++;
|
||||
}
|
||||
}
|
||||
cout << out << endl << cnt1 << endl << cnt2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/01冒泡排序实现.exe
Normal file
BIN
C++代码/CSP04/01冒泡排序实现.exe
Normal file
Binary file not shown.
37
C++代码/CSP04/02-简单排序/01冒泡排序实现.cpp
Normal file
37
C++代码/CSP04/02-简单排序/01冒泡排序实现.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
void bubble(int n){
|
||||
for(int i = 1; i <= n - 1; i++){ // 趟次
|
||||
bool bol = true; // 认为排好序了
|
||||
for(int j = 1; j <= n - i; j++){
|
||||
if(arr[j] > arr[j+1]){
|
||||
swap(arr[j], arr[j+1]);
|
||||
bol = false;
|
||||
}
|
||||
}
|
||||
if(bol){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
bubble(n);
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
38
C++代码/CSP04/02-简单排序/02选择排序实现.cpp
Normal file
38
C++代码/CSP04/02-简单排序/02选择排序实现.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
void selection(int n) {
|
||||
for(int i = 1; i <= n; i++) {
|
||||
int maxx = arr[i]; // 当前这个数是最大的
|
||||
int idx = i;
|
||||
for(int j = i + 1; j <= n; j++) {
|
||||
// 打擂台
|
||||
if(arr[j] > maxx) {
|
||||
maxx = arr[j];
|
||||
idx = j;
|
||||
}
|
||||
}
|
||||
if(arr[i] != maxx) {
|
||||
swap(arr[i], arr[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
selection(n);
|
||||
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/02选择排序实现.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/02选择排序实现.exe
Normal file
Binary file not shown.
36
C++代码/CSP04/02-简单排序/03计算排序后的交换次数.cpp
Normal file
36
C++代码/CSP04/02-简单排序/03计算排序后的交换次数.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, cnt = 0;
|
||||
int arr[100100];
|
||||
|
||||
void insertion(int n){
|
||||
for(int i = 2; i <= n; i++){ // i前面的都是有序的
|
||||
int curr = arr[i]; // 当前乱序的第一个
|
||||
int j = i - 1;
|
||||
while(j >= 1 && arr[j] > curr){
|
||||
cnt++;
|
||||
arr[j+1] = arr[j];
|
||||
j--;
|
||||
}
|
||||
j++;
|
||||
|
||||
arr[j] = curr;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
insertion(n);
|
||||
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl << cnt;
|
||||
return 0;
|
||||
}
|
||||
BIN
C++代码/CSP04/02-简单排序/03计算排序后的交换次数.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/03计算排序后的交换次数.exe
Normal file
Binary file not shown.
35
C++代码/CSP04/02-简单排序/04求第 K 小的数.cpp
Normal file
35
C++代码/CSP04/02-简单排序/04求第 K 小的数.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, k;
|
||||
int arr[100100];
|
||||
|
||||
void bubble(int n){
|
||||
for(int i = 1; i <= n - 1; i++){ // 趟次
|
||||
bool bol = true; // 认为排好序了
|
||||
for(int j = 1; j <= n - i; j++){
|
||||
if(arr[j] > arr[j+1]){
|
||||
swap(arr[j], arr[j+1]);
|
||||
bol = false;
|
||||
}
|
||||
}
|
||||
if(bol){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n >> k;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
bubble(n);
|
||||
|
||||
cout << arr[k];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/04求第 K 小的数.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/04求第 K 小的数.exe
Normal file
Binary file not shown.
38
C++代码/CSP04/02-简单排序/05成绩排名.cpp
Normal file
38
C++代码/CSP04/02-简单排序/05成绩排名.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
string name[100100];
|
||||
int score[100100];
|
||||
|
||||
void bubble(int n){
|
||||
for(int i = 1; i <= n - 1; i++){ // ÌË´Î
|
||||
bool bol = true; // ÈÏΪÅźÃÐòÁË
|
||||
for(int j = 1; j <= n - i; j++){
|
||||
if(score[j] < score[j+1]){
|
||||
bol = false;
|
||||
swap(score[j], score[j+1]);
|
||||
swap(name[j], name[j+1]);
|
||||
}
|
||||
}
|
||||
if(bol){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> name[i] >> score[i];
|
||||
}
|
||||
|
||||
bubble(n);
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << name[i] << " " << score[i] << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/05成绩排名.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/05成绩排名.exe
Normal file
Binary file not shown.
39
C++代码/README.md
Normal file
39
C++代码/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# C++代码(CSP04 上课代码)
|
||||
|
||||
> 本文件夹存放 **2026 秋季班 CSP04** 每节课上课讲解的 OJ 题目参考代码(老师上课敲的版本),按课次分目录。
|
||||
|
||||
## 目录约定
|
||||
|
||||
```
|
||||
C++代码/
|
||||
└── CSP04/
|
||||
├── 01/ # 第1课「01 基础回顾」(对应 OJ 课次 01)
|
||||
│ ├── 小杨的报数游戏.cpp
|
||||
│ ├── 小杨的回文串.cpp
|
||||
│ ├── 小杨的进制数位.cpp
|
||||
│ ├── 小杨的幸运数字.cpp
|
||||
│ └── 小杨有序去重.cpp
|
||||
└── NN/ # 后续课次…
|
||||
```
|
||||
|
||||
- 每课一个数字目录,编号 = OJ 课次编号(`01` 起)。
|
||||
- 文件名 = OJ 题目名,与课程页"课堂练习"里 S0401P1~P5 对应。
|
||||
|
||||
## OJ 定位(重要)
|
||||
|
||||
| 项 | 值 |
|
||||
|------|------|
|
||||
| OJ 平台 | Hydro(Cookie 登录,凭据在仓库 `.env`) |
|
||||
| 课程页 | https://oj.qonnwolf.com/course/6a826183bdde81887a2237b5(2026 秋季班 CSP04) |
|
||||
| 每课作业ID对照 | `.claude/lesson/CSP/CSP04/OJ作业ID-2026秋.md` |
|
||||
| 查数据规则 | `.claude/rules/oj_data.md` |
|
||||
|
||||
> 写 CSP 课评需要 OJ 做题数据时,直接按上面对照表查,**无需再问老师要网址/作业ID**。
|
||||
|
||||
## 编码说明
|
||||
|
||||
早期个别 `.cpp` 以 GBK/ANSI 保存(含中文注释),用 UTF-8 工具打开会乱码;如需统一可转成 UTF-8(转换不会改变程序内容)。
|
||||
|
||||
---
|
||||
|
||||
*维护:橙子老师 · 更新于 2026-09-02*
|
||||
40
C++代码/冒泡排序.cpp
Normal file
40
C++代码/冒泡排序.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
// 冒泡排序
|
||||
int arr[1000];
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
|
||||
for(int i = 1; i <= n - 1; i++){ // i表示的趟数
|
||||
bool bol = true; // 认为没有进行交换
|
||||
for(int j = 1; j <= n - i; j++) { // j表示当前的这个元素 j+1表示下一个元素
|
||||
if(arr[j] > arr[j+1]) {
|
||||
// swap(arr[j], arr[j+1]);
|
||||
int t = arr[j];
|
||||
arr[j] = arr[j+1];
|
||||
arr[j+1] = t;
|
||||
bol = false;
|
||||
}
|
||||
}
|
||||
if(bol){
|
||||
break;
|
||||
}
|
||||
// cout << "第" << i << "趟的结果是:";
|
||||
// print();
|
||||
// cout << endl;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/冒泡排序.exe
Normal file
BIN
C++代码/冒泡排序.exe
Normal file
Binary file not shown.
70
C++代码/学习/01迷宫.cpp
Normal file
70
C++代码/学习/01迷宫.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m, x, y;
|
||||
int cntt[1010][1010];
|
||||
char arr[1010][1010];
|
||||
|
||||
int tot = 0;
|
||||
int sz[1000010];
|
||||
|
||||
int fx[] = {0, 0, 1, 0, -1};
|
||||
int fy[] = {0, 1, 0, -1, 0};
|
||||
|
||||
int q[1000010][3];
|
||||
|
||||
void bfs(int x, int y){
|
||||
int cnt = 1;
|
||||
tot++;
|
||||
|
||||
q[1][1] = x;
|
||||
q[1][2] = y;
|
||||
cntt[x][y] = tot;
|
||||
int head = 1, tail = 1;
|
||||
|
||||
while(head <= tail){
|
||||
int cx = q[head][1];
|
||||
int cy = q[head][2];
|
||||
|
||||
int tx, ty;
|
||||
for(int i = 1; i <= 4; i++){
|
||||
tx = cx + fx[i];
|
||||
ty = cy + fy[i];
|
||||
|
||||
if(tx >= 1 && tx <= n && ty >= 1 && ty <= n && cntt[tx][ty] == 0
|
||||
&& (arr[cx][cy] != arr[tx][ty])){
|
||||
tail++;
|
||||
q[tail][1] = tx;
|
||||
q[tail][2] = ty;
|
||||
cntt[tx][ty] = tot;
|
||||
// cout << "ÎÒ¿ÉÒÔÀ´";
|
||||
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
head++;
|
||||
}
|
||||
sz[tot] = cnt;
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= n; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= n; j++){
|
||||
if(cntt[i][j] == 0) bfs(i, j);
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= m; i++){
|
||||
cin >> x >> y;
|
||||
cout << sz[cntt[x][y]] << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/01迷宫.exe
Normal file
BIN
C++代码/学习/01迷宫.exe
Normal file
Binary file not shown.
16
C++代码/学习/1.cpp
Normal file
16
C++代码/学习/1.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string n;
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
|
||||
for(int i = 0; i < n.size(); i++){
|
||||
if(n[i] == '4') cout << '8';
|
||||
else cout << n[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/1.exe
Normal file
BIN
C++代码/学习/1.exe
Normal file
Binary file not shown.
55
C++代码/学习/奇怪的电梯.cpp
Normal file
55
C++代码/学习/奇怪的电梯.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, a, b;
|
||||
int cnt = 0;
|
||||
int arr[100100];
|
||||
|
||||
int fx[] = {0, 1, -1};
|
||||
|
||||
int q[100000][2]; // ϱê0±íʾ´ÎÊý
|
||||
|
||||
void bfs(int k){
|
||||
int head = 1, tail = 1;
|
||||
q[head][0] = 0;
|
||||
q[head][1] = k;
|
||||
|
||||
while(head <= tail){
|
||||
int curr = q[head][1]; //µ±Ç°Â¥²ã
|
||||
|
||||
int tx;
|
||||
for(int i = 1; i <= 2; i++){
|
||||
tx = curr + fx[i] * arr[curr];
|
||||
|
||||
if(tx >= 1 && tx <= n){
|
||||
tail++;
|
||||
q[tail][0] = q[head][0] + 1;
|
||||
q[tail][1] = tx;
|
||||
|
||||
if(tx == b) {
|
||||
cout << q[tail][0];
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
head++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n >> a >> b;
|
||||
if(a == b){
|
||||
cout << 0;
|
||||
return 0;
|
||||
}
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
bfs(a);
|
||||
|
||||
cout << -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/奇怪的电梯.exe
Normal file
BIN
C++代码/学习/奇怪的电梯.exe
Normal file
Binary file not shown.
66
C++代码/学习/最小拐弯路径.cpp
Normal file
66
C++代码/学习/最小拐弯路径.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int arr[1010][1010];
|
||||
int bol[1010][1010];
|
||||
int s1, s2, e1, e2;
|
||||
int fx[] = {0, 0, 1, 0, -1};
|
||||
int fy[] = {0, 1, 0, -1, 0};
|
||||
|
||||
struct Node {
|
||||
int x;
|
||||
int y;
|
||||
int cnt;
|
||||
};
|
||||
queue<Node> q; //
|
||||
|
||||
void bfs(int x, int y) {
|
||||
Node nd;
|
||||
nd.x = x;
|
||||
nd.y = y;
|
||||
nd.cnt = 0;
|
||||
bol[x][y] = 1;
|
||||
q.push(nd);
|
||||
while(q.size()) {
|
||||
Node head = q.front();
|
||||
|
||||
int cx = head.x;
|
||||
int cy = head.y;
|
||||
int cnt = head.cnt;
|
||||
|
||||
int tx, ty;
|
||||
for(int i = 1; i <= 4; i++) {
|
||||
tx = cx + fx[i];
|
||||
ty = cy + fy[i];
|
||||
while(tx >= 1 && tx <= n && ty >= 1 && ty <= m && arr[tx][ty] == 0) {
|
||||
if(bol[tx][ty] == 0){
|
||||
q.push({tx, ty, cnt + 1});
|
||||
bol[tx][ty] = 1;
|
||||
}
|
||||
if(tx == e1 && ty == e2){
|
||||
cout << cnt;
|
||||
return ;
|
||||
}
|
||||
tx += fx[i];
|
||||
ty += fy[i];
|
||||
}
|
||||
}
|
||||
q.pop();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
for(int j = 1; j <= m; j++) {
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
cin >> s1 >> s2;
|
||||
cin >> e1 >> e2;
|
||||
bfs(s1, s2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/最小拐弯路径.exe
Normal file
BIN
C++代码/学习/最小拐弯路径.exe
Normal file
Binary file not shown.
23
C++代码/学习/未命名2.cpp
Normal file
23
C++代码/学习/未命名2.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
char c;
|
||||
cin >> c;
|
||||
|
||||
// 判断c是大写还是小写
|
||||
if(c >= 'a' && c <= 'z'){
|
||||
// 小写
|
||||
c = c - 'a' + 'A';
|
||||
} else {
|
||||
c = c - 'A' + 'a';
|
||||
}
|
||||
|
||||
cout << c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/未命名2.exe
Normal file
BIN
C++代码/学习/未命名2.exe
Normal file
Binary file not shown.
32
C++代码/学习/未命名4.cpp
Normal file
32
C++代码/学习/未命名4.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
// 循环拆位
|
||||
int num, sum = 0;
|
||||
cin >> num;
|
||||
|
||||
int t = num;
|
||||
while(t > 0){
|
||||
// 第一步 获取最一位
|
||||
int g = t % 10; // %10 获得最后一位
|
||||
|
||||
// 第二步 我们要进行的操作
|
||||
sum = sum * 10 + g;
|
||||
|
||||
// 第三步 去掉最后一位
|
||||
t /= 10;
|
||||
}
|
||||
if(sum == num){
|
||||
cout << "是回文串";
|
||||
} else {
|
||||
cout << "不是回文串";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/未命名4.exe
Normal file
BIN
C++代码/学习/未命名4.exe
Normal file
Binary file not shown.
33
C++代码/学习/未命名5.cpp
Normal file
33
C++代码/学习/未命名5.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
// 判断一个数是不是质数
|
||||
|
||||
int main(){
|
||||
int num;
|
||||
cin >> num;
|
||||
|
||||
bool ok = true; // 一开始我认为这个数是质数
|
||||
|
||||
// 质数(素数):除了1和它本身
|
||||
for(int i = 2; i <= sqrt(num); i++){
|
||||
// 让i 作为除数
|
||||
if(num % i == 0){
|
||||
// i把num整除了
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ok){
|
||||
cout << "是质数";
|
||||
} else {
|
||||
cout << "不是质数";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/未命名5.exe
Normal file
BIN
C++代码/学习/未命名5.exe
Normal file
Binary file not shown.
34
C++代码/学习/未命名7.cpp
Normal file
34
C++代码/学习/未命名7.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
// 拆位:短除法 1234 4321 %10
|
||||
// 1234 1234 /1000 %1000 /100
|
||||
int n, cnt = 1;
|
||||
cin >> n;
|
||||
|
||||
// 先获得这个数的位数
|
||||
int t = n;
|
||||
while(t /= 10){
|
||||
cnt *= 10;
|
||||
}
|
||||
|
||||
cout << cnt;
|
||||
// while(cnt){
|
||||
// int f = n / cnt; // 得到第一位
|
||||
//
|
||||
// // 如果这个数是4 就改成8
|
||||
// if(f == 4){
|
||||
// f = 8;
|
||||
// }
|
||||
// cout << f;
|
||||
//
|
||||
// // 获得后面的几位数
|
||||
// n %= cnt;
|
||||
// cnt /= 10;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/未命名7.exe
Normal file
BIN
C++代码/学习/未命名7.exe
Normal file
Binary file not shown.
25
C++代码/学习/计算能力.cpp
Normal file
25
C++代码/学习/计算能力.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int arr[100100];
|
||||
int dp[100100];
|
||||
int x, y;
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
dp[i] = dp[i - 1] + arr[i];
|
||||
}
|
||||
for(int i = 1; i <= m; i++){
|
||||
cin >> x >> y;
|
||||
cout << dp[y] - dp[x - 1] << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/计算能力.exe
Normal file
BIN
C++代码/学习/计算能力.exe
Normal file
Binary file not shown.
72
C++代码/学习/走出迷宫的最短路径.cpp
Normal file
72
C++代码/学习/走出迷宫的最短路径.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m, z; // z表示当前走了多少个节点
|
||||
int arr[160][160];
|
||||
int s1, s2, e1, e2;
|
||||
|
||||
int fx[] = {0, 0, 1, 0, -1};
|
||||
int fy[] = {0, 1, 0, -1, 0};
|
||||
|
||||
int q[40000][3]; // 下标0表示前上一个点
|
||||
|
||||
void print(int k){
|
||||
if(k == 0) return ;
|
||||
print(q[k][0]); // 先走回到最前面的位置
|
||||
cout << "(" << q[k][1] << "," << q[k][2] << ")";
|
||||
if(k != z) cout << "->";
|
||||
}
|
||||
|
||||
void bfs(int x, int y){
|
||||
q[1][0] = 0;
|
||||
q[1][1] = x;
|
||||
q[1][2] = y;
|
||||
arr[x][y] = 1;
|
||||
int head = 1, tail = 1;
|
||||
|
||||
while(head <= tail){
|
||||
int cx = q[head][1];
|
||||
int cy = q[head][2];
|
||||
|
||||
int tx, ty;
|
||||
for(int i = 1; i <= 4; i++){
|
||||
tx = cx + fx[i];
|
||||
ty = cy + fy[i];
|
||||
|
||||
if(tx >= 1 && tx <= n && ty >= 1 && ty <= m && arr[tx][ty] == 0){
|
||||
tail++;
|
||||
|
||||
q[tail][0] = head;
|
||||
q[tail][1] = tx;
|
||||
q[tail][2] = ty;
|
||||
|
||||
if(tx == e1 && ty == e2){
|
||||
z = tail;
|
||||
print(tail);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
arr[tx][ty] = 1;
|
||||
}
|
||||
}
|
||||
head++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
cin >> s1 >> s2 >> e1 >> e2;
|
||||
|
||||
bfs(s1, s2);
|
||||
|
||||
cout << "no way";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/走出迷宫的最短路径.exe
Normal file
BIN
C++代码/学习/走出迷宫的最短路径.exe
Normal file
Binary file not shown.
55
C++代码/学习/走迷宫.cpp
Normal file
55
C++代码/学习/走迷宫.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
const int MAX = 50;
|
||||
char mapp[MAX][MAX];
|
||||
int step[MAX][MAX];
|
||||
struct Node{
|
||||
int x, y;
|
||||
};
|
||||
queue<Node> q;
|
||||
|
||||
int fx[] = {0, 0, 1, 0, -1};
|
||||
int fy[] = {0, 1, 0, -1, 0};
|
||||
|
||||
void bfs(int x, int y){
|
||||
Node dian;
|
||||
dian.x = x;
|
||||
dian.y = y;
|
||||
step[x][y] = 1;
|
||||
|
||||
q.push(dian);
|
||||
while(q.size()){
|
||||
int cx = q.front().x;
|
||||
int cy = q.front().y;
|
||||
|
||||
int tx, ty;
|
||||
for(int i = 1; i <= 4; i++){
|
||||
tx = cx + fx[i];
|
||||
ty = cy + fy[i];
|
||||
|
||||
if(tx >= 1 && tx <= n && ty >= 1 && ty <= m && mapp[tx][ty] == '.' && step[tx][ty] == 0){
|
||||
q.push({tx, ty});
|
||||
step[tx][ty] = step[cx][cy] + 1;
|
||||
if(tx == n && ty == m) return ;
|
||||
}
|
||||
}
|
||||
q.pop();
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> mapp[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
bfs(1, 1);
|
||||
cout << step[n][m];
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/走迷宫.exe
Normal file
BIN
C++代码/学习/走迷宫.exe
Normal file
Binary file not shown.
24
C++代码/学习/连续数的和.cpp
Normal file
24
C++代码/学习/连续数的和.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, k, cnt = 0;
|
||||
long long dp[70010];
|
||||
|
||||
int main(){
|
||||
cin >> n >> k;
|
||||
for(int i = 1; i <= n; i++){
|
||||
dp[i] = dp[i-1] + i;
|
||||
}
|
||||
|
||||
for(int i = k; i <= n; i++){
|
||||
long long curr = dp[i] - dp[i-k];
|
||||
// 判断这个数是不是某一个数的平方
|
||||
if((int)sqrt(curr) * (int)sqrt(curr) == curr){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
cout << cnt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/连续数的和.exe
Normal file
BIN
C++代码/学习/连续数的和.exe
Normal file
Binary file not shown.
24
C++代码/学习/连续自然数和.cpp
Normal file
24
C++代码/学习/连续自然数和.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
int M;
|
||||
cin >> M;
|
||||
int l = 1, r = 1;
|
||||
long long sum = 0;
|
||||
while (l <= M/2){
|
||||
if (sum < M){
|
||||
sum += r;
|
||||
r++;
|
||||
}else if (sum > M){
|
||||
sum -= l;
|
||||
l++;
|
||||
}else{
|
||||
cout << l << " " << r-1 << endl;
|
||||
sum -= l;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/连续自然数和.exe
Normal file
BIN
C++代码/学习/连续自然数和.exe
Normal file
Binary file not shown.
33
C++代码/插入排序.cpp
Normal file
33
C++代码/插入排序.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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 = 2; i <= n; i++){ // i当前我抽到的这个扑克牌 无序的第一个数
|
||||
int curr = arr[i]; // 记住当前这个牌
|
||||
int j = i - 1; //表示有序的最后一个数
|
||||
|
||||
while(j >= 1 && curr < arr[j]) {
|
||||
arr[j+1] = arr[j]; //
|
||||
j--;
|
||||
}
|
||||
j++;
|
||||
|
||||
arr[j] = curr;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/插入排序.exe
Normal file
BIN
C++代码/插入排序.exe
Normal file
Binary file not shown.
27
C++代码/未命名1.cpp
Normal file
27
C++代码/未命名1.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
int a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
|
||||
// 从小到大排序
|
||||
if(a > b){
|
||||
swap(a, b);
|
||||
}
|
||||
|
||||
if(b > c){
|
||||
swap(b, c);
|
||||
}
|
||||
|
||||
// if(a > b){
|
||||
// swap(a, b);
|
||||
// }
|
||||
cout << a << " " << b << " " << c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/未命名1.exe
Normal file
BIN
C++代码/未命名1.exe
Normal file
Binary file not shown.
49
C++代码/未命名2.cpp
Normal file
49
C++代码/未命名2.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
// 冒泡排序:通过相邻元素的比较和交换,使得每一趟循环都能将当前未排序部分的最大值“冒泡”到末尾
|
||||
for(int i = 1; i <= n - 1; i++) { // 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;
|
||||
}
|
||||
}
|
||||
if(ok){
|
||||
break;
|
||||
}
|
||||
cout << "第" << i << "趟:";
|
||||
print();
|
||||
}
|
||||
|
||||
// 原数组 5 3 8 1 4
|
||||
// 第一趟 3 5 1 4 8
|
||||
// 第二趟 3 1 4 5 8
|
||||
// 第三趟 1 3 4 5 8
|
||||
// 第四趟 1 3 4 5 8
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/未命名2.exe
Normal file
BIN
C++代码/未命名2.exe
Normal file
Binary file not shown.
48
C++代码/未命名3.cpp
Normal file
48
C++代码/未命名3.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n - 1; i++){ // 当前要交换的这个位置
|
||||
int maxx = arr[i];
|
||||
int idx = i;
|
||||
for(int j = i + 1; j <= n; j++){ // j表示要和maxx进行比较的那个值的下标
|
||||
// 打擂台
|
||||
if(arr[j] > maxx){
|
||||
maxx = arr[j];
|
||||
idx = j;
|
||||
}
|
||||
}
|
||||
|
||||
swap(arr[i], arr[idx]);
|
||||
cout << "第" << i << "趟:" ;
|
||||
print();
|
||||
}
|
||||
|
||||
print();
|
||||
|
||||
// 原数组 5 3 8 1 4
|
||||
// 第一趟 8 3 5 1 4
|
||||
// 第二趟 8 5 3 1 4
|
||||
// 第三趟 8 5 4 1 3
|
||||
// 第四趟 8 5 4 3 1
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/未命名3.exe
Normal file
BIN
C++代码/未命名3.exe
Normal file
Binary file not shown.
25
C++代码/未命名4.cpp
Normal file
25
C++代码/未命名4.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int main(){
|
||||
int n;
|
||||
int arr[100100];
|
||||
cin>>n;
|
||||
for(int i=1;i<=n;i++){
|
||||
cin>>arr[i];
|
||||
}
|
||||
for(int i=1;i<=n-1;i++){
|
||||
int maxx=arr[i];
|
||||
int idx=i;
|
||||
for(int j=i+1;j<=n;j++) {
|
||||
if(arr[j]>maxx){
|
||||
maxx=arr[j];
|
||||
idx=j;
|
||||
}
|
||||
}
|
||||
swap(arr[idx],arr[i]);
|
||||
}
|
||||
for(int i=1;i<=n;i++){
|
||||
cout<<arr[i]<<" ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
BIN
C++代码/未命名4.exe
Normal file
BIN
C++代码/未命名4.exe
Normal file
Binary file not shown.
33
C++代码/选择排序.cpp
Normal file
33
C++代码/选择排序.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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; i++){ // i就是当前这个位置 找到一个最值,然后进行交换
|
||||
int maxx = arr[i]; // 当前的最大值
|
||||
int idx = i;
|
||||
for(int j = i + 1; j <= n; j++){
|
||||
// 打擂台
|
||||
if(arr[j] > maxx){
|
||||
maxx = arr[j];
|
||||
idx = j; // 记住最大值下标
|
||||
}
|
||||
}
|
||||
|
||||
swap(arr[idx], arr[i]);
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/选择排序.exe
Normal file
BIN
C++代码/选择排序.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user