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 0934c1c

Browse files
committed
「蓝桥」0322 第 27 场 蓝桥月赛
1 parent a72cb69 commit 0934c1c

File tree

6 files changed

+284
-0
lines changed

6 files changed

+284
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
int n = 16;
8+
int ans = (n + 1) * n / 2;
9+
cout << ans << endl;
10+
}
11+
12+
signed main() {
13+
ios::sync_with_stdio(false);
14+
cin.tie(nullptr);
15+
16+
int t = 1;
17+
// cin >> t;
18+
while (t--) solve();
19+
return 0;
20+
}
21+
/*
22+
抓猪拿国一【算法赛】
23+
*/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
string s;
8+
cin >> s;
9+
10+
int n = s.size();
11+
ll ans = 0;
12+
vector<ll> l(n), r(n);
13+
14+
// 统计每个位置之前 'l' 的数量
15+
int pc = 0;
16+
for (int i = 0; i < n; ++i) {
17+
if (s[i] == 'l') {
18+
pc++;
19+
}
20+
l[i] = pc;
21+
}
22+
// 统计每个位置之后 'n' 的数量
23+
int nc = 0;
24+
for (int i = n - 1; i >= 0; --i) {
25+
if (s[i] == 'n') {
26+
nc++;
27+
}
28+
r[i] = nc;
29+
}
30+
// 枚举 'a' 的位置,累加答案
31+
for (int i = 1; i < n - 1; ++i) {
32+
if (s[i] == 'a') {
33+
ans += l[i - 1] * r[i + 1];
34+
}
35+
}
36+
cout << ans << endl;
37+
}
38+
39+
signed main() {
40+
ios::sync_with_stdio(false);
41+
cin.tie(nullptr);
42+
43+
int t = 1;
44+
// cin >> t;
45+
while (t--) solve();
46+
return 0;
47+
}
48+
/*
49+
蓝桥字符【算法赛】
50+
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
10+
vector<int> a(n), b(n);
11+
vector<pair<int, int> > c(n);
12+
for (int i = 0; i < n; ++i) {
13+
cin >> a[i] >> b[i];
14+
c[i] = {a[i] - b[i], i};
15+
}
16+
sort(c.rbegin(), c.rend());
17+
18+
ll ans = 0;
19+
for (int i = 0; i < n; ++i) {
20+
if (i < n / 2) {
21+
ans += a[c[i].second];
22+
} else {
23+
ans += b[c[i].second];
24+
}
25+
}
26+
cout << ans << endl;
27+
}
28+
29+
signed main() {
30+
ios::sync_with_stdio(false);
31+
cin.tie(nullptr);
32+
33+
int t = 1;
34+
// cin >> t;
35+
while (t--) solve();
36+
return 0;
37+
}
38+
/*
39+
蓝桥大使【算法赛】
40+
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
10+
vector<int> a(n + 1), b(n + 1);
11+
for (int i = 1; i <= n; ++i) {
12+
cin >> a[i];
13+
}
14+
sort(a.begin(), a.end());
15+
16+
ll ans = 0;
17+
for (int i = 1; i <= n; ++i) {
18+
cin >> b[i];
19+
int l = i, r = n, p = n + 1;
20+
while (l <= r) {
21+
int mid = (l + r) >> 1;
22+
if (a[mid] > b[i]) {
23+
p = mid;
24+
r = mid - 1;
25+
} else {
26+
l = mid + 1;
27+
}
28+
}
29+
ans += n - p + 1;
30+
}
31+
cout << ans << endl;
32+
}
33+
34+
signed main() {
35+
ios::sync_with_stdio(false);
36+
cin.tie(nullptr);
37+
38+
int t = 1;
39+
// cin >> t;
40+
while (t--) solve();
41+
return 0;
42+
}
43+
/*
44+
拳头对决【算法赛】
45+
*/
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
const int mod = 1e9 + 7;
6+
7+
void solve() {
8+
int n, c;
9+
cin >> n >> c;
10+
11+
map<int, vector<int> > vec;
12+
for (int i = 0; i < n; ++i) {
13+
int v;
14+
cin >> v;
15+
vec[v].push_back(i);
16+
}
17+
18+
ll ans = 1;
19+
for (const auto &w: vec) {
20+
auto p = w.second;
21+
int m = p.size();
22+
ll cnt = m + 1; // 不监控或监控一台电脑的方案数
23+
for (int i = 0; i < m - 1; ++i) {
24+
int l = i + 1, r = m - 1;
25+
while (l < r) {
26+
int mid = (l + r + 1) >> 1;
27+
if (p[mid] - p[i] <= c) {
28+
l = mid;
29+
} else {
30+
r = mid - 1;
31+
}
32+
}
33+
if (p[r] - p[i] <= c) {
34+
cnt += r - i; // 满足条件的 (i,j) 对数
35+
cnt %= mod;
36+
}
37+
}
38+
ans *= cnt;
39+
ans %= mod;
40+
}
41+
cout << ans - 1 << endl; // 减去所有国家都不监控的方案
42+
}
43+
44+
signed main() {
45+
ios::sync_with_stdio(false);
46+
cin.tie(nullptr);
47+
48+
int t = 1;
49+
// cin >> t;
50+
while (t--) solve();
51+
return 0;
52+
}
53+
/*
54+
未来竞赛【算法赛】
55+
*/
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
const int N = 1e5 + 10;
7+
int n, t;
8+
vector<int> a(N), b(N);
9+
10+
bool check(int x) {
11+
if (a[1] > x) return false;
12+
int cnt = 1, s = x - a[1];
13+
for (int i = 2; i <= n; ++i) {
14+
if (a[i] > x) return false;
15+
if (b[i - 1] + a[i] <= s) {
16+
s -= b[i - 1] + a[i];
17+
} else {
18+
if (s >= b[i - 1]) {
19+
cnt++;
20+
s = x - a[i];
21+
} else {
22+
int d = b[i - 1] - s;
23+
if (d > x) {
24+
cnt += d / x + (d % x != 0);
25+
d = d % x;
26+
s = x - d;
27+
} else {
28+
cnt++;
29+
s = x - d;
30+
}
31+
if (a[i] > s) {
32+
cnt++;
33+
s = x - a[i];
34+
} else {
35+
s -= a[i];
36+
}
37+
}
38+
}
39+
}
40+
return cnt <= t;
41+
}
42+
43+
void solve() {
44+
cin >> n >> t;
45+
for (int i = 1; i <= n; ++i) cin >> a[i];
46+
for (int i = 1; i <= n; ++i) cin >> b[i];
47+
48+
int l = 1, r = 3600, res = -1;
49+
while (l <= r) {
50+
int mid = (l + r) >> 1;
51+
if (check(mid)) {
52+
r = mid - 1, res = mid;
53+
} else {
54+
l = mid + 1;
55+
}
56+
}
57+
cout << res << endl;
58+
}
59+
60+
signed main() {
61+
ios::sync_with_stdio(false);
62+
cin.tie(nullptr);
63+
64+
int t = 1;
65+
// cin >> t;
66+
while (t--) solve();
67+
return 0;
68+
}
69+
/*
70+
备份比赛数据【算法赛】
71+
*/

0 commit comments

Comments
(0)

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