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,23 @@
#include <iostream>
using namespace std;
int func(int x) {
if (x <= 3)
return x * 2 - 1;
else if (x >= 6)
return func(x - 3) - 2;
else
return func(x + 1) + x;
}
int main() {
cout << func(14);
// f(14)=f(11)-2;
// f(11)=f(8)-2
// f(8)=f(5)-2
// f(5)=f(6)+5
// f(6)=f(3)-2
// f(3)=5
return 0;
}

View File

@@ -0,0 +1,9 @@
#include <bits/stdc++.h>
using namespace std;
// Hello world
int main() {
char s[15];
cin >> s; // 原因:Hello world中存在空格,而cin会只读取前半部分Hello,所以长度是5
cout << strlen(s);
return 0;
}

View File

@@ -0,0 +1,13 @@
#include <iostream>
using namespace std;
int a[101];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int s = a[0] + a[1] + a[2];
for (int i = 1; i < n - 2; i++) s = max(s, a[i] + a[i + 1] + a[i + 2]);
cout << s << endl;
return 0;
}

View File

@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 120;
int a[N], b[N];
const int INF = 0x3f3f3f3f;
/*
5
5 7 5 5 3 | 5 7 5 5 3
答案:4
*/
int n, sum, avg;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
a[i + n] = a[i]; // 破环成链
}
avg = sum / n; // 平均数
int mi = INF; // 最少次数,给初始值最大
for (int i = 0; i < n; i++) { // 按每个石子堆为起点
for (int j = 0; j < n; j++) b[j] = a[i + j]; // 从原始的破环成链数组中拷贝出来现在的临时数组
int cnt = 0;
for (int j = 0; j < n - 1; j++) {
cnt += abs(b[j] - avg); // 需要调整几个石子到下一个石子堆
b[j + 1] += b[j] - avg; // 下一个石子堆接着这些石子
b[j] = avg; // j调整为平均值,其实这句没有发挥作用,可省略
}
// 以第i个石子为起点的讨论结束,判断是不是我们需要的最优解
mi = min(mi, cnt);
}
cout << mi << endl;
return 0;
}

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 31;
char a[N][N];
int n, m, cnt;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j]; // a,b,c
for (int e = 2; e <= min(m, n); e++) { // 枚举每个小正方形的边长
for (int i = 0; i <= n - e; i++) { // 起点i
for (int j = 0; j <= m - e; j++) { // 起点j
bool f = true;
for (int x = 0; x < e; x++) { // 遍历正方形中所有的其它位置,判断是不是与左上角的一致
for (int y = 0; y < e; y++) {
if (a[i][j] != a[i + x][j + y]) {
f = false;
break;
}
}
if (!f) break;
}
if (f) cnt++;
}
}
}
cout << cnt << endl;
return 0;
}

View File

@@ -0,0 +1,61 @@
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
double a[N];
int n;
int f1[N], f2[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
// 以每棵树为保留的,并且是最高的那棵树,分别求出最长上升序列长度x 和 最长下降序列长度y, x+y-1就是最终保留的整体序列长度,
// 去掉的数量就是 n-(x+y-1)的值。然后求min()
// 需要注意的是默认值设置为-1,比如 5 4 3 2 1 ,我们取哪棵为最高点都行不通,不存在左侧上侧到峰值的情况,右侧即使符合也不行的。
// 求最长上升
for (int i = 1; i <= n; i++) {
f1[i] = 1;
for (int j = 1; j < i; j++)
if (a[i] > a[j]) f1[i] = max(f1[i], f1[j] + 1);
}
// 求最长下降
for (int i = n; i >= 1; i--) {
f2[i] = 1;
for (int j = n; j > i; j--)
if (a[i] > a[j]) f2[i] = max(f2[i], f2[j] + 1);
}
// f1[i],f2[i]全都是1,那么输出-1
bool flag = true;
for (int i = 1; i <= n; i++)
if (f1[i] != 1) {
flag = false;
break;
}
if (flag) {
cout << -1 << endl;
exit(0);
}
flag = true;
for (int i = 1; i <= n; i++)
if (f2[i] != 1) {
flag = false;
break;
}
if (flag) {
cout << -1 << endl;
exit(0);
}
int mx = -1;
for (int i = 1; i <= n; i++) {
int t = f1[i] + f2[i];
mx = max(mx, t);
}
cout << n - mx + 1 << endl;
return 0;
}

View File

@@ -0,0 +1,2 @@
10
1.0 2.3 1.2 1.7 1.1 2.0 1.8 1.8 1.2 1.9

View File

@@ -0,0 +1,9 @@
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int main() {
// 加快读入
ios::sync_with_stdio(false), cin.tie(0);
cout << "dd" << endl;
return 0;
}

View File

@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int a[110];
int l, r;
int n;
int sum;
int s1, s2;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> l >> r;
if (sum < l * n || sum > r * n) {
printf("-1");
exit(0);
}
for (int i = 1; i <= n; i++){
if (a[i] > r) s1 += a[i] - r;
if (a[i] < l) s2 += l - a[i];
}
cout << max(s1, s2);
return 0;
}

View File

@@ -0,0 +1,3 @@
https://ccgao.blog.csdn.net/article/details/134725679
https://tiku.scratchor.com/paper/view/z8k4y0xsf0ue8xlh