Skip to content

Commit e005209

Browse files
committed
add niuke code tk2
1 parent 890eea3 commit e005209

5 files changed

Lines changed: 111 additions & 5 deletions

File tree

  • .vs
  • niuke
    • contest
      • 小白月赛106/xiaobai2
      • 牛客2025年1024程序员节娱乐赛
        • A牛可乐打怪
        • F困难数学题2之你是AI
    • daily_problem/25_10-18翻之

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

niuke/contest/小白月赛106/xiaobai2/2.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ int main()
1313
cin >> a[i];
1414
}
1515

16-
// 只需要计算一次最大最小值
16+
// 只需要计算一次最大最小值
1717
int max_val = *max_element(a.begin(), a.end());
1818
int min_val = *min_element(a.begin(), a.end());
1919

20-
// 直接计算最终平均值和操作次数
20+
// 直接计算最终平均值和操作次数
2121
int average = (max_val + min_val + 1) / 2;
22-
long long cnt = 0; // 使用long long防止溢出
22+
long long cnt = 0; // 使用long long防止溢出
2323

24-
// 一次性计算所有需要的操作次数
24+
// 一次性计算所有需要的操作次数
2525
for (int i = 0; i < n; i++)
2626
{
2727
if (a[i] < average)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
int main() {
6+
ios::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
9+
ll a, n;
10+
cin >> a >> n;
11+
12+
//×îÉÙ¹¥»÷´ÎÊý
13+
int k_min = (n + a - 1) / a;
14+
15+
ll dmg1 = (n + k_min - 1) / k_min;
16+
ll total1 = k_min * dmg1;
17+
18+
ll dmg2 = (n + k_min) / (k_min + 1);
19+
ll total2 = (k_min + 1) * dmg2;
20+
21+
ll best_dmg;
22+
if (total1 < total2)best_dmg = dmg1;
23+
else if (total1 > total2)best_dmg = dmg2;
24+
else {
25+
best_dmg = max(dmg1, dmg2);
26+
}
27+
cout << a - best_dmg;
28+
return 0;
29+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
using i128 = __int128_t;
4+
5+
const long long MOD_INPUT = 251024; // 输入取模
6+
const long long MOD_OUTPUT = 998224353LL; // 输出取模
7+
8+
// 返回 1^2 + ... + n^2,使用 __int128 保证不溢出
9+
i128 prefix_square_sum_i128(long long n) {
10+
if (n <= 0) return 0;
11+
i128 a = (i128)n;
12+
i128 res = a * (a + 1) * (2 * a + 1) / 6;
13+
return res;
14+
}
15+
16+
// 区间平方和 [l,r]
17+
i128 range_sum_i128(long long l, long long r) {
18+
if (l > r) return 0;
19+
return prefix_square_sum_i128(r) - prefix_square_sum_i128(l - 1);
20+
}
21+
22+
// __int128 输出为字符串
23+
string i128_to_string(i128 x) {
24+
if (x == 0) return "0";
25+
bool neg = x < 0;
26+
if (neg) x = -x;
27+
string s;
28+
while (x > 0) {
29+
s.push_back('0' + (int)(x % 10));
30+
x /= 10;
31+
}
32+
if (neg) s.push_back('-');
33+
reverse(s.begin(), s.end());
34+
return s;
35+
}
36+
37+
// 对输出取模
38+
i128 mod_output(i128 x) {
39+
x %= MOD_OUTPUT;
40+
if (x < 0) x += MOD_OUTPUT;
41+
return x;
42+
}
43+
44+
int main() {
45+
ios::sync_with_stdio(false);
46+
cin.tie(nullptr);
47+
48+
int T;
49+
if (!(cin >> T)) return 0;
50+
51+
while (T--) {
52+
long long l, r;
53+
cin >> l >> r;
54+
55+
// 对输入取模(题目要求)
56+
l %= MOD_INPUT;
57+
r %= MOD_INPUT;
58+
59+
// 如果取模后 l > r,则答案为 0
60+
if (l > r) {
61+
cout << 0 << '\n';
62+
continue;
63+
}
64+
65+
// 计算区间平方和
66+
i128 ans = range_sum_i128(l, r);
67+
68+
// 输出前对 998224353 取模
69+
ans = mod_output(ans);
70+
71+
cout << i128_to_string(ans) << '\n';
72+
}
73+
74+
return 0;
75+
}

niuke/daily_problem/25_10-18翻之/1.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ int main() {
4646
cout << max_cnt << '\n';
4747

4848
return 0;
49-
}
49+
}
50+
51+

0 commit comments

Comments
 (0)