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 233c416

Browse files
committed
「蓝桥」0208 第 26 场 蓝桥入门赛
1 parent 3f1cdea commit 233c416

File tree

7 files changed

+250
-0
lines changed

7 files changed

+250
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.Arrays;
2+
import java.util.Scanner;
3+
4+
public class a {
5+
public static void main(String[] args) {
6+
Scanner scanner = new Scanner(System.in);
7+
System.out.println(solve());
8+
}
9+
10+
private static String solve() {
11+
char[] s = "snake".toCharArray();
12+
Arrays.sort(s);
13+
return String.valueOf(s);
14+
}
15+
}
16+
/*
17+
蛇年大吉【算法赛】
18+
*/
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+
6+
void solve() {
7+
int n;
8+
string a, b;
9+
cin >> n >> a >> b;
10+
11+
// 统计字符串 a 中 0 和 1 的数量
12+
int x = std::count(a.begin(), a.end(), '0');
13+
int y = n - x;
14+
15+
// 统计字符串 b 中 0 和 1 的数量
16+
int d = std::count(b.begin(), b.end(), '0');
17+
int e = n - d;
18+
19+
// 计算最大异或值中 1 的个数
20+
int ans = min(x, e) + min(d, y);
21+
cout << ans << endl;
22+
}
23+
24+
signed main() {
25+
ios::sync_with_stdio(false);
26+
cin.tie(nullptr);
27+
28+
int t = 1;
29+
// cin >> t;
30+
while (t--) solve();
31+
return 0;
32+
}
33+
/*
34+
对联【算法赛】
35+
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package lq250208;
2+
3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
6+
public class LQ250208T2 {
7+
static int n;
8+
static char[] a, b;
9+
10+
public static void main(String[] args) {
11+
Scanner scanner = new Scanner(System.in);
12+
n = scanner.nextInt();
13+
a = scanner.next().toCharArray();
14+
b = scanner.next().toCharArray();
15+
System.out.println(solve());
16+
}
17+
18+
private static String solve() {
19+
Arrays.sort(a);
20+
reverseSort(b);
21+
22+
int ans = 0;
23+
for (int i = 0; i < n; i++) {
24+
ans += a[i] ^ b[i];
25+
}
26+
return String.valueOf(ans);
27+
}
28+
29+
static void reverseSort(char[] arr) {
30+
Arrays.sort(arr);
31+
for (int l = 0, r = arr.length - 1; l < r; l++, r--) {
32+
char tmp = arr[l];
33+
arr[l] = arr[r];
34+
arr[r] = tmp;
35+
}
36+
}
37+
}
38+
/*
39+
对联【算法赛】
40+
*/
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+
string s;
8+
cin >> s;
9+
10+
int x = 0, y = 0;
11+
for (const auto &b: s) {
12+
if (b == 'U') y++;
13+
if (b == 'D') y--;
14+
if (b == 'L') x++;
15+
if (b == 'R') x--;
16+
}
17+
if (s.size() % 2 == 1) {
18+
cout << -1 << endl;
19+
} else {
20+
int ans = min(abs(x), abs(y));
21+
ans += abs(abs(x) - abs(y)) / 2;
22+
cout << ans << endl;
23+
}
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+
38+
相似题目: 3443. K 次修改后的最大曼哈顿距离
39+
https://leetcode.cn/problems/maximum-manhattan-distance-after-k-changes/description/
40+
*/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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> v(n);
11+
for (int i = 0; i < n; ++i) {
12+
cin >> v[i];
13+
}
14+
std::sort(v.begin(), v.end());
15+
16+
priority_queue<int, vector<int>, greater<int>> pq;
17+
pq.push(0);
18+
for (int i = 0; i < n; ++i) {
19+
int val = pq.top();
20+
if (val < v[i]) {
21+
pq.pop();
22+
pq.push(val + 1);
23+
} else {
24+
pq.push(1);
25+
}
26+
}
27+
cout << pq.size() << endl;
28+
}
29+
30+
signed main() {
31+
ios::sync_with_stdio(false);
32+
cin.tie(nullptr);
33+
34+
int t = 1;
35+
// cin >> t;
36+
while (t--) solve();
37+
return 0;
38+
}
39+
/*
40+
舞狮【算法赛】
41+
*/
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+
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+
a[i] %= k;
14+
}
15+
16+
std::sort(a.begin(), a.end());
17+
int ans = a[n - 1] - a[0];
18+
for (int i = 0; i < n - 1; ++i) {
19+
ans = min(ans, a[i] + k - a[i + 1]);
20+
}
21+
cout << ans << endl;
22+
}
23+
24+
signed main() {
25+
ios::sync_with_stdio(false);
26+
cin.tie(nullptr);
27+
28+
int t = 1;
29+
// cin >> t;
30+
while (t--) solve();
31+
return 0;
32+
}
33+
/*
34+
扑克较量【算法赛】
35+
*/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
const int mod = 1e9 + 7;
6+
7+
ll ksm(ll x, ll k, ll mo = mod) {
8+
ll ans = 1;
9+
while (k) {
10+
if (k & 1) ans = ans * x % mo;
11+
x = x * x % mo;
12+
k >>= 1;
13+
}
14+
return ans;
15+
}
16+
17+
void solve() {
18+
ll a, b, c, n;
19+
cin >> a >> b >> c >> n;
20+
21+
ll d = a * b % mod * c % mod;
22+
ll ans = ksm(d, ksm(2, n, mod - 1), mod);
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+
38+
可以归纳出,经过 N 次变换后,乘积 P_N = P_{0}^{2^N}。
39+
因此,我们只需要计算结果初始乘积 P0,然后计算 P0 的 2^N 次方即可。
40+
需要注意的是,2N 可能很大,因此我们需要使用快速幂并搭配欧拉降幂来完成计算。
41+
*/

0 commit comments

Comments
(0)

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