Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0dff7df

Browse files
committed
「蓝桥」0222 第 26 场 蓝桥月赛
1 parent 233c416 commit 0dff7df

File tree

6 files changed

+238
-0
lines changed

6 files changed

+238
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package lq250222;
2+
3+
import java.util.Scanner;
4+
5+
public class LQ250222T1 {
6+
public static void main(String[] args) {
7+
Scanner scanner = new Scanner(System.in);
8+
System.out.println(solve());
9+
}
10+
11+
private static String solve() {
12+
int ans = (2025 + 15 - 1) / 15;
13+
return String.valueOf(ans);
14+
}
15+
}
16+
/*
17+
好汤圆【算法赛】
18+
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
int n, m;
8+
cin >> n >> m;
9+
10+
int x = 1;
11+
ll ans = 0;
12+
for (int i = 0; i < n; ++i) {
13+
int l, r;
14+
cin >> l >> r;
15+
if (x < l) {
16+
ans += l - x;
17+
x = l;
18+
} else if (x > r) {
19+
ans += x - r;
20+
x = r;
21+
}
22+
}
23+
cout << ans << endl;
24+
}
25+
26+
signed main() {
27+
ios::sync_with_stdio(false);
28+
cin.tie(nullptr);
29+
30+
int t = 1;
31+
// cin >> t;
32+
while (t--) solve();
33+
return 0;
34+
}
35+
/*
36+
灯笼猜谜【算法赛】
37+
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
int n, k;
8+
cin >> n >> k;
9+
10+
vector<int> a(n);
11+
for (int i = 0; i < n; ++i) {
12+
cin >> a[i];
13+
}
14+
sort(a.begin(), a.begin() + k + 1);
15+
a[1] += a[0];
16+
a[0] = 0;
17+
sort(a.begin(), a.end());
18+
19+
ll ans = 0;
20+
for (int i = 0; i < n / 2; ++i) {
21+
ans += a[i];
22+
}
23+
cout << ans << endl;
24+
}
25+
26+
signed main() {
27+
ios::sync_with_stdio(false);
28+
cin.tie(nullptr);
29+
30+
int t = 1;
31+
// cin >> t;
32+
while (t--) solve();
33+
return 0;
34+
}
35+
/*
36+
元宵分配【算法赛】
37+
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
const int mod = 1e9 + 7;
6+
const int N = 1e6 + 5;
7+
vector<ll> f(N);
8+
9+
void init() {
10+
f[1] = 1;
11+
f[2] = 2;
12+
for (int i = 3; i < N; ++i) {
13+
f[i] = (f[i - 1] + (i - 1) * f[i - 2]) % mod;
14+
}
15+
}
16+
17+
void solve() {
18+
int n;
19+
cin >> n;
20+
cout << f[n] << endl;
21+
}
22+
23+
signed main() {
24+
ios::sync_with_stdio(false);
25+
cin.tie(nullptr);
26+
27+
init();
28+
int t = 1;
29+
cin >> t;
30+
while (t--) solve();
31+
return 0;
32+
}
33+
/*
34+
摆放汤圆【算法赛】
35+
*/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
int n;
8+
cin >> n;
9+
vector<int> a(n);
10+
for (int i = 0; i < n; ++i) {
11+
cin >> a[i];
12+
}
13+
14+
// 排序并去重
15+
sort(a.begin(), a.end());
16+
auto last = unique(a.begin(), a.end());
17+
a.erase(last, a.end());
18+
int m = a.size();
19+
20+
// 对于每个 k,计算最大合集大小
21+
for (int k = 1; k <= n; ++k) {
22+
int ans = 1;
23+
int v = a[0];
24+
while (true) {
25+
int pos = lower_bound(a.begin(), a.end(), v + k) - a.begin();
26+
if (pos == m) {
27+
break;
28+
}
29+
v = a[pos];
30+
ans++;
31+
}
32+
cout << ans << " \n"[k == n];
33+
}
34+
}
35+
36+
signed main() {
37+
ios::sync_with_stdio(false);
38+
cin.tie(nullptr);
39+
40+
int t = 1;
41+
// cin >> t;
42+
while (t--) solve();
43+
return 0;
44+
}
45+
/*
46+
元宵交友【算法赛】
47+
*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
const int MAXN = 1e5 + 10;
7+
int n;
8+
9+
struct P {
10+
int x, y;
11+
} a[MAXN];
12+
13+
void solve() {
14+
cin >> n;
15+
for (int i = 1; i <= n; ++i) cin >> a[i].x;
16+
for (int i = 1; i <= n; ++i) cin >> a[i].y;
17+
18+
priority_queue<pair<int, int> > q1, q2;
19+
q1.push({a[1].x + a[1].y, 1});
20+
q2.push({a[1].x - a[1].y, 1});
21+
22+
ll ans = 0;
23+
24+
for (int l = 1, r = 2; l <= n; ++r) {
25+
while (!q1.empty()) {
26+
auto c = q1.top();
27+
if (a[r].x + a[r].y <= c.first) {
28+
q1.pop();
29+
l = max(l, c.second + 1);
30+
} else {
31+
break;
32+
}
33+
}
34+
q1.push({a[r].x + a[r].y, r});
35+
36+
while (!q2.empty()) {
37+
auto c = q2.top();
38+
if (a[r].x - a[r].y <= c.first) {
39+
q2.pop();
40+
l = max(l, c.second + 1);
41+
} else {
42+
break;
43+
}
44+
}
45+
q2.push({a[r].x - a[r].y, r});
46+
47+
ans += r - l;
48+
}
49+
cout << ans << endl;
50+
}
51+
52+
signed main() {
53+
ios::sync_with_stdio(false);
54+
cin.tie(nullptr);
55+
56+
int t = 1;
57+
// cin >> t;
58+
while (t--) solve();
59+
return 0;
60+
}
61+
62+
/*
63+
灯笼大乱斗【算法赛】
64+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /