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 9ce829e

Browse files
committed
「蓝桥」0607 第 29 场 蓝桥·算法挑战赛
1 parent 96316ac commit 9ce829e

File tree

5 files changed

+490
-0
lines changed

5 files changed

+490
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
// 请在此输入您的代码
6+
cout << "1 3 1 9" << endl;
7+
return 0;
8+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package lq250607;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.PrintWriter;
7+
import java.util.StringTokenizer;
8+
9+
public class LQ250607T2 {
10+
static FastReader scanner = new FastReader();
11+
static PrintWriter out = new PrintWriter(System.out);
12+
13+
public static void main(String[] args) {
14+
int t = 1;
15+
// t = scanner.nextInt();
16+
while (t-- > 0) solve();
17+
out.flush();
18+
}
19+
20+
private static void solve() {
21+
int n = scanner.nextInt();
22+
int s = scanner.nextInt();
23+
int e = scanner.nextInt();
24+
int d = scanner.nextInt();
25+
26+
// s->e
27+
int res1 = getDis(n, s, e); // 他只能顺时针向前移动
28+
29+
int res2 = getDis(n, (s + d) % n, e); // 向前移动 d 格区域
30+
31+
int res3 = getDis(n, ((s - d) % n + n) % n, e); // 向后移动 d 格区域
32+
33+
int ans = min(res1 % n, res2 % n, res3 % n);
34+
out.println(ans);
35+
}
36+
37+
static int getDis(int n, int s, int e) {
38+
return (e >= s) ? e - s : (e + n - s);
39+
}
40+
41+
static int min(int... values) {
42+
int mixValue = Integer.MAX_VALUE;
43+
for (int i : values) {
44+
if (i < mixValue) {
45+
mixValue = i;
46+
}
47+
}
48+
return mixValue;
49+
}
50+
51+
static class FastReader {
52+
private final BufferedReader bufferedReader;
53+
private StringTokenizer stringTokenizer;
54+
55+
public FastReader() {
56+
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
57+
}
58+
59+
public String next() {
60+
while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
61+
try {
62+
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
63+
} catch (IOException e) {
64+
e.printStackTrace();
65+
}
66+
}
67+
return stringTokenizer.nextToken();
68+
}
69+
70+
public int nextInt() {
71+
return Integer.parseInt(next());
72+
}
73+
74+
public long nextLong() {
75+
return Long.parseLong(next());
76+
}
77+
78+
public double nextDouble() {
79+
return Double.parseDouble(next());
80+
}
81+
82+
public String nextLine() {
83+
String str = "";
84+
try {
85+
if (stringTokenizer.hasMoreTokens()) {
86+
str = stringTokenizer.nextToken("\n");
87+
} else {
88+
str = bufferedReader.readLine();
89+
}
90+
} catch (IOException e) {
91+
e.printStackTrace();
92+
}
93+
return str;
94+
}
95+
}
96+
}
97+
/*
98+
赛飞儿之旅【算法赛】
99+
100+
5 2 1 0
101+
5 2 1 2
102+
*/
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package lq250607;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.PrintWriter;
7+
import java.util.StringTokenizer;
8+
9+
public class LQ250607T3 {
10+
static FastReader scanner = new FastReader();
11+
static PrintWriter out = new PrintWriter(System.out);
12+
13+
public static void main(String[] args) {
14+
int t = 1;
15+
// t = scanner.nextInt();
16+
while (t-- > 0) solve();
17+
out.flush();
18+
}
19+
20+
private static void solve() {
21+
char[] s = scanner.next().toCharArray();
22+
int n = s.length;
23+
int[][] cnt = new int[4][26];
24+
for (int i = 0; i < n; i++) {
25+
cnt[i % 4][s[i] - 'a']++;
26+
}
27+
28+
int[] x = new int[4];
29+
int cb = cnt[0]['b' - 'a'];
30+
int cl = cnt[1]['l' - 'a'];
31+
int cu = cnt[2]['u' - 'a'];
32+
int ce = cnt[3]['e' - 'a'];
33+
x[0] = min(cb, cl, cu, ce);
34+
35+
cb = cnt[1]['b' - 'a'];
36+
cl = cnt[2]['l' - 'a'];
37+
cu = cnt[3]['u' - 'a'];
38+
ce = cnt[0]['e' - 'a'];
39+
x[1] = min(cb, cl, cu, ce);
40+
41+
cb = cnt[2]['b' - 'a'];
42+
cl = cnt[3]['l' - 'a'];
43+
cu = cnt[0]['u' - 'a'];
44+
ce = cnt[1]['e' - 'a'];
45+
x[2] = min(cb, cl, cu, ce);
46+
47+
cb = cnt[3]['b' - 'a'];
48+
cl = cnt[0]['l' - 'a'];
49+
cu = cnt[1]['u' - 'a'];
50+
ce = cnt[2]['e' - 'a'];
51+
x[3] = min(cb, cl, cu, ce);
52+
53+
// 贪心选起点
54+
int ans = 0;
55+
int i = 0;
56+
int M = n - 4; // 最大起点索引
57+
while (i <= M) {
58+
int c = i % 4;
59+
if (x[c] > 0) {
60+
// 取这个起点
61+
ans++;
62+
x[c]--;
63+
i += 4; // 跳过 3 个重叠位置
64+
} else {
65+
i++;
66+
}
67+
}
68+
out.println(ans);
69+
}
70+
71+
static int min(int... values) {
72+
int mixValue = Integer.MAX_VALUE;
73+
for (int i : values) {
74+
if (i < mixValue) {
75+
mixValue = i;
76+
}
77+
}
78+
return mixValue;
79+
}
80+
81+
static class FastReader {
82+
private final BufferedReader bufferedReader;
83+
private StringTokenizer stringTokenizer;
84+
85+
public FastReader() {
86+
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
87+
}
88+
89+
public String next() {
90+
while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
91+
try {
92+
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
93+
} catch (IOException e) {
94+
e.printStackTrace();
95+
}
96+
}
97+
return stringTokenizer.nextToken();
98+
}
99+
100+
public int nextInt() {
101+
return Integer.parseInt(next());
102+
}
103+
104+
public long nextLong() {
105+
return Long.parseLong(next());
106+
}
107+
108+
public double nextDouble() {
109+
return Double.parseDouble(next());
110+
}
111+
112+
public String nextLine() {
113+
String str = "";
114+
try {
115+
if (stringTokenizer.hasMoreTokens()) {
116+
str = stringTokenizer.nextToken("\n");
117+
} else {
118+
str = bufferedReader.readLine();
119+
}
120+
} catch (IOException e) {
121+
e.printStackTrace();
122+
}
123+
return str;
124+
}
125+
}
126+
}
127+
/*
128+
blue密钥【算法赛】
129+
*/
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
def main():
2+
l_val, r_val = map(int, input().split())
3+
4+
def solve(n):
5+
if n <= 0:
6+
return 0
7+
max_len = 10
8+
num_str = str(n)
9+
len_n = len(num_str)
10+
digits = [0] * (max_len - len_n) + [int(d) for d in num_str]
11+
12+
from functools import lru_cache
13+
14+
@lru_cache(maxsize=None)
15+
def dp(i, tight, found, state):
16+
if i == max_len:
17+
return (1, 0) if found else (0, 0)
18+
19+
total_count = 0
20+
total_sum = 0
21+
low = 0
22+
high = digits[i] if tight else 9
23+
24+
for d in range(low, high + 1):
25+
new_tight = tight and (d == high)
26+
power = 10 ** (9 - i)
27+
28+
if found:
29+
count_next, sum_next = dp(i + 1, new_tight, True, 0)
30+
if count_next > 0:
31+
total_count += count_next
32+
total_sum += d * power * count_next + sum_next
33+
else:
34+
new_state = next_state(state, d)
35+
if new_state == 4:
36+
count_next, sum_next = dp(i + 1, new_tight, True, 0)
37+
if count_next > 0:
38+
total_count += count_next
39+
total_sum += d * power * count_next + sum_next
40+
else:
41+
count_next, sum_next = dp(i + 1, new_tight, False, new_state)
42+
if count_next > 0:
43+
total_count += count_next
44+
total_sum += d * power * count_next + sum_next
45+
46+
return (total_count, total_sum)
47+
48+
def next_state(s, d):
49+
if s == 0:
50+
if d == 4:
51+
return 1
52+
else:
53+
return 0
54+
elif s == 1:
55+
if d == 9:
56+
return 2
57+
elif d == 4:
58+
return 1
59+
else:
60+
return 0
61+
elif s == 2:
62+
if d == 3:
63+
return 3
64+
elif d == 4:
65+
return 1
66+
else:
67+
return 0
68+
elif s == 3:
69+
if d == 1:
70+
return 4
71+
elif d == 4:
72+
return 1
73+
else:
74+
return 0
75+
76+
count, total_sum = dp(0, True, False, 0)
77+
return total_sum
78+
79+
ans = solve(r_val) - solve(l_val - 1)
80+
print(ans)
81+
82+
83+
if __name__ == '__main__':
84+
main()

0 commit comments

Comments
(0)

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