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,26 @@
#include <bits/stdc++.h>
using namespace std;
const int V[6] = {1, 5, 10, 50, 100, 500};
int C[6];
int A; // 要组装的货币数量
/*
3 2 1 3 0 2
620
答案:
6
*/
int main() {
for (int i = 0; i < 6; i++) cin >> C[i];
cin >> A;
int ans = 0;
// 由大到小枚举
for (int i = 5; i >= 0; i--) {
int t = min(A / V[i], C[i]); // 能取多少,受两个条件限制:可以取的数量,包含的数量,两者取小
A -= t * V[i]; // 扣除掉
ans += t; // 维护结果
}
cout << ans << endl;
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
struct Node {
int st;
int ed;
const bool operator<(const Node &W) {
return ed < W.ed;
}
} w[N];
/*
5
1 2 4 6 8
3 5 7 9 10
答案:
3
*/
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> w[i].st;
for (int i = 0; i < n; i++) cin >> w[i].ed;
sort(w, w + n);
int ans = 0, t = 0; // 设置的个数,前一个的结束时间
for (int i = 0; i < n; i++) {
if (w[i].st > t) {
t = w[i].ed;
ans++;
}
}
cout << ans << endl;
return 0;
}

View File

@@ -0,0 +1,36 @@
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int r, n, X[1100];
int ans;
int main() {
#ifndef ONLINE_JUDGE
freopen("POJ3069.in", "r", stdin);
#endif
while (cin >> r >> n && ~r && ~n) {
ans = 0;
for (int i = 0; i < n; i++) cin >> X[i];
sort(X, X + n);
int i = 0;
while (i < n) {
int s = X[i++]; // s:没有被覆盖的最左边点的位置
while (i < n && X[i] <= s + r) i++; // 找到无法覆盖的点
int p = X[i - 1]; // 新加上标注点的位置
while (i < n && X[i] <= p + r) i++; // 将此点右侧,所有可覆盖的点走完
ans++;
/*
Q:为什么一定要执行两次while呢?不能是一次while吗?
答:本题贪心的逻辑:排完序,标注点越往后越好,这样使的标点最少。
① 算法逻辑就是一路向前,找到一个大于规则半径R的序号,然后,回退一个,在这个位置上安排一个。
② 这个位置上安排完了,它可以照亮后面的R个范围,需要一路向前进行排除。
③ 到达了一个无法覆盖的位置,那么必须在这里安排一个标注点吗?当然不是,因为我们是贪心的,越往后越好,
左边已经照顾不到它了,但它的右边可以照顾它啊!所以第二个while循环登场~
*/
}
printf("%d\n", ans);
}
return 0;
}

View File

@@ -0,0 +1,5 @@
0 3
10 20 20
10 7
70 30 1 7 15 20 50
-1 -1

View File

@@ -0,0 +1,37 @@
#include <iostream>
using namespace std;
const int N = 2010;
char s[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
int a = 0, b = n - 1, idx = 0;
while (a <= b) {
bool left = false;
for (int i = 0; a + i <= b; i++) { // 若首位相等则比较下一个
if (s[a + i] < s[b - i]) {
left = true;
break;
}
if (s[a + i] > s[b - i]) {
left = false;
break;
}
}
if (left)
putchar(s[a++]);
else
putchar(s[b--]);
idx++;
if (idx == 80) {
idx = 0;
puts("");
}
}
return 0;
}

View File

@@ -0,0 +1,6 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
return 0;
}