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,10 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
LL n;
scanf("%lld", &n);
printf("%lld", n - 1);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
char c;
int n;
scanf("%c %d", &c, &n);
if (c + n > 'z') printf("*");
else printf("%c", c + n);
return 0;
}

View File

@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
/*
4
-1 3 5 3
3
*/
int a[N];
int k, n, x;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
cin >> x;
for (int i = 1; i <= n; i++) {
if (a[i] == x) {
k = i;
printf("%d", k);
break;
}
}
if (k == 0)
printf("-1");
return 0;
}

View File

@@ -0,0 +1,43 @@
#include <bits/stdc++.h>
using namespace std;
struct Node {
int num;
int step;
};
const int N = 1010;
int n, m;
queue<Node> q;
int st[N];
void bfs() {
q.push({n, 0});
while (q.size()) {
auto x = q.front();
q.pop();
if (x.num == m) {
printf("%d\n", x.step);
break;
}
if (!st[x.num + 1]) {
q.push({x.num + 1, x.step + 1});
st[x.num + 1] = 1;
}
if (!st[x.num - 1]) {
q.push({x.num - 1, x.step + 1});
st[x.num - 1] = 1;
}
if (!st[x.num * 2]) {
q.push({x.num * 2, x.step + 1});
st[x.num * 2] = 1;
}
}
}
int main() {
cin >> n >> m;
bfs();
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
// OJ地址
// https://www.acwing.com/problem/content/150/
// 黄海题解
// https://www.cnblogs.com/littlehb/p/15488791.html
//小顶堆
priority_queue<int, vector<int>, greater<int>> q;
int res;
int main() {
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
q.push(x);
}
while (q.size() > 1) {
int a = q.top();
q.pop();
int b = q.top();
q.pop();
res += a + b;
q.push(a + b);
}
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,29 @@
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n;
cin >> n;
priority_queue<int> q;
while (n--) {
int x;
cin >> x;
q.push(-x);
}
int res = 0;
while (q.size() > 1) {
int a = q.top();
q.pop();
int b = q.top();
q.pop();
res -= a + b;
q.push(a + b);
}
printf("%d\n", res);
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int>> q;
int res;
int main() {
int n;
cin >> n;
while (n) {
int x;
cin >> x;
q.push(x);
}
while (q.size() > 1) {
int a = q.top();
q.pop();
int b = q.top();
q.pop();
res += a + b;
q.push(a + b);
}
printf("%d", res);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB