Skip to content

Commit 986a2db

Browse files
committed
feat: kick-start 2022 round b
1 parent 1b5e3d3 commit 986a2db

File tree

7 files changed

+159
-10
lines changed

7 files changed

+159
-10
lines changed

kick-start/2022/RoundB/a.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let input = ''
2+
3+
process.stdin.on('data', data => input += data)
4+
process.stdin.on('end', () => {
5+
const lines = input.split('\n')
6+
const [t] = lines[0].split(' ').map(Number)
7+
for (let kase = 1; kase <= t; kase++) {
8+
let [r, a, b] = lines[kase].split(' ').map(Number)
9+
let ans = 0; let f = 1
10+
while (r) {
11+
ans += Math.PI * r * r
12+
if (f) r = Math.floor(r * a)
13+
else r = Math.floor(r / b)
14+
f = !f
15+
}
16+
console.log(`Case #${kase}: ${ans}`)
17+
}
18+
})

kick-start/2022/RoundB/b-naive.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <algorithm>
2+
#include <cmath>
3+
#include <iostream>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
typedef long long LL;
8+
int t;
9+
LL a;
10+
string s;
11+
#define N 3000000
12+
LL b[N];
13+
int n;
14+
15+
int solve() {
16+
int ans = 0;
17+
for (LL b = 1; b <= a; b++) {
18+
auto s = to_string(b);
19+
auto t = to_string(b);
20+
reverse(t.begin(), t.end());
21+
if (s == t && (a % b == 0)) ans++;
22+
}
23+
return ans;
24+
}
25+
26+
int main() {
27+
cin >> t;
28+
for (int i = 1; i <= t; i++) {
29+
cin >> a;
30+
printf("Case #%d: %d\n", i, solve());
31+
}
32+
return 0;
33+
}

kick-start/2022/RoundB/b.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <algorithm>
2+
#include <cmath>
3+
#include <iostream>
4+
using namespace std;
5+
6+
typedef long long LL;
7+
int t;
8+
LL a;
9+
string s;
10+
#define N 3000000
11+
LL b[N];
12+
int n;
13+
14+
int solve() {
15+
int ans = 0;
16+
for (int i = 0; i < n; i++) {
17+
if (a % b[i] == 0) ans++;
18+
if (b[i] >= a) break;
19+
}
20+
return ans;
21+
}
22+
23+
int main() {
24+
cin >> t;
25+
for (LL x = 1;; x++) {
26+
auto s = to_string(x), t = to_string(x);
27+
reverse(t.begin(), t.end());
28+
LL y = atoll((s + t).c_str());
29+
b[n++] = y;
30+
for (int i = 0; i <= 9; i++) {
31+
LL y = atoll((s + to_string(i) + t).c_str());
32+
b[n++] = y;
33+
}
34+
if (x <= 9) {
35+
b[n++] = x;
36+
}
37+
if (y >= 2e10) break;
38+
}
39+
sort(b, b + n);
40+
for (int i = 1; i <= t; i++) {
41+
cin >> a;
42+
printf("Case #%d: %d\n", i, solve());
43+
}
44+
return 0;
45+
}

kick-start/2022/RoundB/b.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
let input = ''
2+
3+
process.stdin.on('data', data => input += data)
4+
process.stdin.on('end', () => {
5+
const lines = input.split('\n')
6+
const [t] = lines[0].split(' ').map(Number)
7+
for (let kase = 1; kase <= t; kase++) {
8+
const a = BigInt(lines[kase])
9+
let ans = 0
10+
for (let x = Number(1); x <= Number(1e5 - 1); x++) {
11+
if (x <= 9) if (a % BigInt(x) === BigInt(0)) ans++
12+
let y = BigInt(String(x) + String(x).split('').reverse().join(''))
13+
if (a % y === BigInt(0)) ans++
14+
for (let i = 0; i <= 9; i++) {
15+
y = BigInt(String(x) + i + String(x).split('').reverse().join(''))
16+
if (a % y === BigInt(0)) ans++
17+
}
18+
}
19+
console.log(`Case #${kase}: ${ans}`)
20+
}
21+
})

kick-start/2022/RoundB/c.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
let input = ''
2+
3+
process.stdin.on('data', data => input += data)
4+
process.stdin.on('end', () => {
5+
const lines = input.split('\n')
6+
const [t] = lines[0].split(' ').map(Number)
7+
for (let kase = 1; kase <= t; kase++) {
8+
const [_, d] = lines[kase * 2 - 1].split(' ').map(Number)
9+
const v = lines[kase * 2].split(' ').map(Number)
10+
const n = v.length
11+
/*
12+
dp[i][j][k] = 将区间 i, j 全部变成 k 的开销
13+
Math.min(dp[i1][j][num(i, i1)], dp[i][j1][num(j1, j)])
14+
*/
15+
const cache = {}
16+
const solve = (i, j, k) => {
17+
console.assert(i >= 0 && i < n)
18+
console.assert(j >= 0 && j < n)
19+
if (cache[`${i}_${j}_${k}`] != null) {
20+
return cache[`${i}_${j}_${k}`]
21+
}
22+
while (v[i] === k) i++
23+
while (v[j] === k) j--
24+
if (i > j) return 0
25+
const k1 = v[i]; const k2 = v[j]
26+
const d1 = Math.abs(k1 - k); const d2 = Math.abs(k2 - k)
27+
const ans = Math.min(solve(i, j, k1) + Math.min(d1, d - d1), solve(i, j, k2) + Math.min(d2, d - d2))
28+
if (ans < 0) console.log(i, j, k, k1, k2, d, d1, d2)
29+
return cache[`${i}_${j}_${k}`] = ans
30+
}
31+
console.log(`Case #${kase}: ${solve(0, n - 1, 0)}`)
32+
}
33+
})

matcher.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <ctime>
66
#include <iostream>
77

8-
const std::string bf = "kick-start/2021/RoundE/a.naive.cpp";
9-
const std::string algo = "kick-start/2021/RoundE/a.cpp";
8+
const std::string bf = "kick-start/2022/RoundB/b-naive.cpp";
9+
const std::string algo = "kick-start/2022/RoundB/b.cpp";
1010
const std::string randomGenerator = "random.cpp";
1111

1212
/*
@@ -28,20 +28,20 @@ int mySystem(const char* command) {
2828

2929
int main() {
3030
mySystem(("g++ -std=c++17 -o random.out " + randomGenerator).c_str());
31-
// mySystem(
32-
// ("g++ -std=c++17 -o bf.out " + bf).c_str());
33-
// mySystem(
34-
// ("g++ -std=c++17 -o algo.out " + algo).c_str());
31+
mySystem(
32+
("g++ -std=c++17 -o bf.out " + bf).c_str());
33+
mySystem(
34+
("g++ -std=c++17 -o algo.out " + algo).c_str());
3535
for (int T = 1;; T++) {
3636
// 生成随机数据
3737
mySystem("./random.out > data.in");
3838
// 记录运行的 CPU 时间
3939
double st = clock();
4040
// 暴力解法输出正确答案
41-
mySystem("node kick-start/2021/RoundH/c.js < data.in > data.ans");
41+
mySystem("./bf.out < data.in > data.ans");
4242
double ed = clock();
4343
// 优化解法输出待检查答案
44-
mySystem("node kick-start/2021/RoundH/d.js < data.in > data.out");
44+
mySystem("./algo.out < data.in > data.out");
4545

4646
if (mySystem("diff data.out data.ans")) {
4747
puts("\033[1;31mWrong Answer\033[0m");

random.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ int main() {
2323
cout << n << endl;
2424
for (int i = 1; i <= n; i++) {
2525
{
26-
cout << 10 << endl
27-
<< getRandStr(10);
26+
cout << getRandStr(5);
2827
cout << endl;
2928
}
3029
}

0 commit comments

Comments
 (0)