This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 30;
LL a[N];
int main() {
a[1] = 1;
a[2] = 2;
for (int i = 3; i < N; i++)
a[i] = a[i - 1] + a[i - 2];
for (int i = 1; i <= 20; i++)
printf("%lld ", a[i]);
return 0;
}

View File

@@ -0,0 +1,15 @@
#include <bits/stdc++.h>
using namespace std;
//a2b3
//2
string s;
int cnt;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] >= '0' && s[i] <= '9')cnt++;
printf("%d", cnt);
return 0;
}

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
/**
模拟测试用例:
189.22 172.235 150.344 153.45 169.78 170.904 190.985 180.85
196.00 197.346
1 2 2 2 1 2 1 2 1 1
*/
const int N = 15;
struct Node {
int bj;
double h;
const bool operator<(const Node &b) const {
if (bj != b.bj) return bj < b.bj;
// 一班同学,身高矮的在前
if (bj == 1) return h < b.h;
// 二班同学,身高高的在前
return h > b.h;
}
} a[N];
int main() {
int n = 10;
for (int i = 1; i <= n; i++) cin >> a[i].h;
for (int i = 1; i <= n; i++) cin >> a[i].bj;
// 按规则排序
sort(a + 1, a + 1 + n);
// 输出
for (int i = 1; i <= 10; i++)
printf("%d %.2f\n", a[i].bj, a[i].h);
return 0;
}

View File

@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
using namespace std;
/**
模拟测试用例:
189.22 172.235 150.344 153.45 169.78 170.904 190.985 180.85 196.00 197.346
1 2 2 2 1 2 1 2 1 1
*/
const int N = 15;
double a[N], c[N], d[N];
int b[N], cl, dl;
int main() {
int n = 10;
for (int i = 1; i <= n; i++) cin >> a[i]; // 身高
for (int i = 1; i <= n; i++) cin >> b[i]; // 班级号
for (int i = 1; i <= n; i++)
if (b[i] == 1) // 一班的入c数组
c[++cl] = a[i];
else // 二班的入d数组
d[++dl] = a[i];
sort(c + 1, c + 1 + 5); // lppoi 由小到大
sort(d + 1, d + 1 + 5); // 由小到大
// 正序输出
for (int i = 1; i <= 5; i++)
printf("%d %.2f\n", 1, c[i]);
// 倒序输出
for (int i = 5; i; i--)
printf("%d %.2f\n", 2, d[i]);
return 0;
}

View File

@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
using namespace std;
/**
模拟测试用例:
189.22 172.235 150.344 153.45 169.78 170.904 190.985 180.85 196.00 197.346
1 2 2 2 1 2 1 2 1 1
*/
const int N = 15;
double a[N], c[N], d[N];
int b[N], cl, dl;
int main() {
int n = 10;
for (int i = 1; i <= n; i++) cin >> a[i]; // 身高
for (int i = 1; i <= n; i++) cin >> b[i]; // 班级号
for (int i = 1; i <= n; i++)
if (b[i] == 1) // 一班的入c数组
c[++cl] = a[i];
else // 二班的入d数组
d[++dl] = a[i];
sort(c + 1, c + 1 + 5); // 由小到大
sort(d + 1, d + 1 + 5, greater<double>()); // 由大到小
// 正序输出
for (int i = 1; i <= 5; i++)
printf("%d %.2f\n", 1, c[i]);
// 正序输出
for (int i = 1; i <= 5; i++)
printf("%d %.2f\n", 2, d[i]);
return 0;
}

View File

@@ -0,0 +1,15 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 120;
LL a[N];
int main() {
int n;
cin >> n;
a[1] = 1, a[2] = 2;
for (int i = 3; i <= n; i++) a[i] = a[i - 1] + a[i - 2];
printf("%lld ", a[n]);
return 0;
}

View File

@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
const int N = 110;
LL f[N];
int main() {
int n, T;
cin >> T;
while (T--) {
cin >> n;
f[1] = 1, f[2] = 3;
for (int i = 3; i <= n; i++)
f[i] = f[i - 1] + 2 * f[i - 2];
printf("%lld\n", f[n]);
}
}

View File

@@ -0,0 +1,56 @@
#include <bits/stdc++.h>
/**
3 4
P P P P
P O P X
P O X P
O P P P
答案:10
*/
using namespace std;
const int N = 110;
char a[N][N];
struct Node {
int x;
int y;
int step;
};
queue<Node> q;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int cnt;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
// 记录初始病人
if (a[i][j] == 'X') q.push({i, j, 0}), cnt++;
}
// n分钟
while (q.size()) {
auto u = q.front();
q.pop();
// 执行n分钟
if (u.step == n) break;
// 四个方向
for (int i = 0; i <= 3; i++) {
int tx = u.x + dx[i];
int ty = u.y + dy[i];
if (tx >= 1 && tx <= m && ty >= 1
&& ty <= m && a[tx][ty] == 'P') {
a[tx][ty] = 'X';
cnt++;
q.push({tx, ty, u.step + 1});
}
}
}
printf("%d ", cnt);
return 0;
}

View File

@@ -0,0 +1,39 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char a[N][N];
struct Node {
int x;
int y;
int step;
};
queue<Node> q;
int dx[] = {-1, 0, 1, 0}; // 上右下左
int dy[] = {0, 1, 0, -1}; // 上右下左
int cnt;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 'X') q.push({i, j, 0}),cnt++;
}
while (q.size()) {
auto u = q.front();
q.pop();
if (u.step == n) break;
for (int i = 0; i <= 3; i++) {
int tx = u.x + dx[i];
int ty = u.y + dy[i];
if (tx >= 1 && a[tx][ty] == 'P' && tx <= m && ty >= 1 && ty <= m) {
a[tx][ty] = 'X';
cnt++;
q.push({tx, ty, u.step + 1});
}
}
}
printf("%d ",cnt);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB