Precreation contest files

This commit is contained in:
2026-02-11 11:28:23 +07:00
parent 0a8ea477bb
commit cb9f7cab30
134 changed files with 1848 additions and 0 deletions

BIN
misc/bdhsg_1015/a.out Executable file

Binary file not shown.

21
misc/bdhsg_1015/max3.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("max3.inp", "r", stdin);
int n;
cin >> n;
vector<int> a(n);
for (int &i : a)
cin >> i;
int res = 0;
for (int i = 0; i < n - 2; i++)
res = max(res, a[i] + a[i + 1] + a[i + 2]);
cout << res << '\n';
}

2
misc/bdhsg_1015/max3.inp Normal file
View File

@@ -0,0 +1,2 @@
6
1 3 4 2 7 9

View File

@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("search.inp", "r", stdin);
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int &i : a)
cin >> i;
if (x - 1 > n || x < 0) {
cout << -1 << '\n';
return 0;
} else {
x = a[x - 1];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
// cout << a[i] << '\n';
if (a[i] == x) {
cout << i + 1 << ' ';
cnt++;
}
}
cout << '\n';
cout << ((cnt == 0) ? -1 : cnt) << '\n';
}

View File

@@ -0,0 +1,2 @@
6 2
1 3 3 5 7 3

View File

View File

BIN
misc/binary-search/cpp.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("ghepcap.inp", "r", stdin);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
// 89 90 91 99 100 101
int res = 0;
for (int j = 0; j < n; j++) {
int l = 0, r = j;
// int ans = a[n - 1];
while (l < r) {
int mid = (l + r) / 2;
if (10 * a[mid] < a[j] * 9) {
l = mid + 1;
} else {
r = mid;
// ans = min(ans, mid);
}
}
// res += j - ans;
res += j - l;
}
cout << res << '\n';
}

View File

@@ -0,0 +1,4 @@
6
100 89 90 101 91 99

View File

@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
#include <ios>
using namespace std;
int a[100000];
int n, m;
int checker(int k) {
int ret = 0;
for (int i = 0; i < n; i++) {
ret += k / a[i];
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("p145sumg.inp", "r", stdin);
cin >> n >> m;
int l = 1, r;
for (int i = 0; i < n; i++) {
cin >> a[i];
r = max(r, a[i]);
}
r *= m;
int res = r;
while (l < r) {
int mid = (l + r) / 2;
if (checker(mid) >= m) {
r = mid;
res = min(mid, res);
} else {
l = mid + 1;
}
}
cout << res << "\n";
}

View File

@@ -0,0 +1,8 @@
7 10
3
8
3
6
9
2
4

View File

@@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int n, m;
int check(int k) {
int res = 0;
for (int i = 0; i < n; i++) {
if (a[i] - k > 0)
res += a[i] - k;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("ptit126j.inp", "r", stdin);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
// 10 15 17 20
int l = 0, r = a[n - 1];
int res = a[n - 1];
while (l < r) {
int mid = (l + r) / 2;
if (check(mid) >= m) {
// cout << mid << "\n";
res = mid;
l = mid + 1;
} else {
r = mid;
}
}
cout << res << '\n';
}

View File

@@ -0,0 +1,2 @@
5 20
4 42 40 26 46

View File

@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int n, m;
int checker(const vector<int> &_a, int k) {
int _n = n;
for (auto i : _a) {
while (i > k) {
i -= k;
_n -= k;
}
if (i > 0) {
_n - k
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("toy.inp", "r", stdin);
cin >> n >> m;
vector<int> a(n);
for (auto &i : a)
cin >> i;
int l = 0, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (checker(a, mid)) {
r = mid;
} else {
l = mid + 1;
}
}
}

View File

@@ -0,0 +1,3 @@
5 2
4
7

View File

@@ -0,0 +1,6 @@
5
ABCD
EFGHIJK
TINHOCTRE
ABCD
EFGHIJK

View File

@@ -0,0 +1,4 @@
3
34
3
30

View File

@@ -0,0 +1,3 @@
3 11
3 4 2
123 0 45

BIN
misc/chuyen-de-xau/a.out Executable file

Binary file not shown.

45
misc/chuyen-de-xau/b2.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include <iostream>
using namespace std;
int segn[300];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for (int j = 0; j < 300; j++)
segn[j] = 0;
string S;
cin >> S;
const int n = S.length();
int res1 = 0;
int res2 = 0;
int l = 0, r = 1;
int i = 0;
while (r < n) {
if (S[l] == S[r])
r++;
else {
segn[i] = r - l;
l = r;
r++;
i++;
}
}
segn[i] = r - l;
i++;
for (int k = 0; k < i; k++) {
res1 = max(res1, segn[k]);
if (segn[k + 1] == 1) {
res2 = max(res2, segn[k] + segn[k + 1] + segn[k + 2]);
}
if (k != 0 || k != n - 1) {
res2 = max(res2, segn[k] + 1);
}
}
cout << res1 << '\n';
cout << res2 << '\n';
}

28
misc/chuyen-de-xau/b3.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("B3.INP", "r", stdin);
map<string, char> hash;
int q;
cin >> q;
for (int i = 0; i < q; i++) {
string a;
cin >> a;
// cout << a;
if (hash.find(a) == hash.end()) {
hash[a] = 1;
} else {
hash[a] = 0;
}
}
for (const auto i : hash) {
if (i.second == 1)
cout << i.first << '\n';
}
}

31
misc/chuyen-de-xau/b4.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;
string S[100];
bool check(const string &a, const string &b) {
const string ab = a + b, ba = b + a;
if (stoi(ab) < stoi(ba))
return false;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("B4.INP", "r", stdin);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
S[i] = a;
}
sort(S, S + n, check);
for (int i = 0; i < n; i++) {
cout << S[i];
}
cout << '\n';
}

38
misc/chuyen-de-xau/b5.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
vector<char> digits;
for (char c : s) {
if (isdigit(c))
digits.push_back(c);
}
int m = digits.size();
string result = "";
int pos = 0;
for (int need = 5; need > 0; need--) {
char best = '0';
int bestPos = pos;
for (int i = pos; i <= m - need; i++) {
if (digits[i] > best) {
best = digits[i];
bestPos = i;
}
}
result.push_back(best);
pos = bestPos + 1;
}
cout << result;
return 0;
}

23
misc/chuyen-de-xau/b6.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int p, k;
cin >> p >> k;
vector<int> a(p), s(p);
for (int &i : a)
cin >> i;
for (int &i : s)
cin >> i;
deque<int> stack;
for (int i = 0; i < p; i++) {
while (a[i]--) {
}
}
}

30
misc/chuyen-de-xau/b7.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
int counter[(int)('z' - 'a')];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a;
cin >> a;
for (const auto i : a) {
counter[i - 'a']++;
}
int sum = 0;
for (const auto i : counter) {
sum += i;
}
int max_x = 0;
char max_c;
for (int i = 0; i < 'z' - 'a'; i++) {
if (counter[i] > max_x) {
max_x = counter[i];
max_c = 'a' + i;
}
}
cout << sum << ' ' << max_c << '\n';
}

22
misc/chuyen-de-xau/b8.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;
string words[20];
bool checker(const string &a, const string &b) { return a.size() < b.size(); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
freopen("b8.inp", "r", stdin);
int n = 0;
while (cin >> words[n] && n < 20)
n++;
stable_sort(words, words + n, checker);
for (int i = 0; i < n; i++) {
cout << words[i] << " ";
}
cout << '\n';
}

View File

@@ -0,0 +1 @@
acb abcde abcd abc

22
misc/hsg-hn-2025/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug C++ (input.inp)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": ["<", "${fileBasenameNoExtension}.inp"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build C++",
"MIMode": "gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty printing",
"text": "-enable-pretty-printing"
}
]
}
]
}

22
misc/hsg-hn-2025/.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build C++",
"type": "shell",
"command": "g++",
"args": [
"-std=gnu++17",
"-O2",
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

BIN
misc/hsg-hn-2025/a.out Executable file

Binary file not shown.

BIN
misc/hsg-hn-2025/denlong Executable file

Binary file not shown.

View File

@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x;
cin >> n >> k >> x;
vector<vector<int>> hash(9, vector<int>(n, 0));
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (i == 0)
hash[a][i] = 1;
else
hash[a][i] = hash[a][i - 1] + 1;
}
}

View File

@@ -0,0 +1,2 @@
6 2 2
1 9 3 2 3 5

View File

View File

@@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6;
int a[MAX_N];
int main() {
freopen("muasam.inp", "r", stdin);
freopen("muasam.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, l, r;
cin >> n >> l >> r;
for (int i = 0; i < n; i++)
cin >> a[i];
int res = 1e9;
sort(a, a + n);
int L = 0, R = n - 1;
while (L < R) {
int sum = a[L] + a[R];
if (sum > r)
R--;
else if (sum < l)
L++;
else {
res = min(res, sum);
R--;
}
}
cout << res << '\n';
}

22
misc/hsg-hp-2025/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug C++ (input.inp)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": ["<", "${fileBasenameNoExtension}.inp"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build C++",
"MIMode": "gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty printing",
"text": "-enable-pretty-printing"
}
]
}
]
}

22
misc/hsg-hp-2025/.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build C++",
"type": "shell",
"command": "g++",
"args": [
"-std=gnu++17",
"-O2",
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

BIN
misc/hsg-hp-2025/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,24 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
int res = 0;
string output = "";
for (int i = a.length() - 1; i >= 0; i--) {
if ('0' <= a[i] && a[i] <= '9')
res += (int)(a[i] - '0');
else
output += a[i];
}
cout << res << '\n';
if (output == "")
cout << -1 << '\n';
else
cout << output << '\n';
}

View File

@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e7;
char is_prime[max_n + 1];
void sieve() {
for (int i = 0; i <= max_n; i++)
is_prime[i] = 1;
is_prime[0] = 0;
is_prime[1] = 0;
// 2 check
for (int i = 4; i <= max_n; i += 2)
is_prime[i] = 0;
// other
for (int i = 3; i * i <= max_n; i += 2)
if (is_prime[i])
for (int j = i * i; j <= max_n; j += i)
is_prime[j] = 0;
}
int solve() {
int n;
cin >> n;
if (!is_prime[n])
return 0;
int digit_sum = 0;
while (n) {
digit_sum += n % 10;
n /= 10;
}
if (!is_prime[digit_sum])
return 0;
return 1;
}
int main() {
sieve();
int q;
cin >> q;
int res = 0;
while (q--) {
res += solve();
}
cout << res << "\n";
}

View File

@@ -0,0 +1,2 @@
6
2 3 19 23 29 17

View File

@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int m, n, S;
cin >> m >> n >> S;
for (int i = 0; i < m * n; i++)
cin >> a[i];
sort(a, a + m * n);
int l = 0, r = m * n - 1;
int cur_max = -1;
while (l < r) {
if (a[l] + a[r] > S)
r--;
else {
cur_max = max(cur_max, a[l] + a[r]);
l++;
}
}
cout << cur_max << '\n';
}

View File

@@ -0,0 +1,4 @@
3 4 10
6 7 8 9
5 6 7 8
9 8 8 7

BIN
misc/hsg-hp-2025/cbai4 Executable file

Binary file not shown.

View File

@@ -0,0 +1,56 @@
#include <bits/stdc++.h>
using namespace std;
void solve() {
vector<deque<int>> char_pos(26);
int n, q;
string S;
cin >> n >> q >> S;
vector<int> is_exist(n, 1);
set<int> exist_char;
// O(n)
for (int i = 0; i < n; i++) {
char_pos[S[i] - 'A'].push_back(i);
}
// O(1)
for (int i = 0; i < 26; i++)
if (!char_pos[i].empty())
exist_char.insert(i);
while (q--) {
if (exist_char.empty())
break;
int t;
cin >> t;
int target_char;
if (t == 0)
target_char = *exist_char.begin();
else
target_char = *exist_char.rbegin();
int target_idx = char_pos[target_char].front();
char_pos[target_char].pop_front();
is_exist[target_idx] = 0;
if (char_pos[target_char].empty())
exist_char.erase(target_char);
}
for (int i = 0; i < n; i++)
if (is_exist[i])
cout << S[i];
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}

View File

@@ -0,0 +1,3 @@
10 4
ADBAACDABC
0 1 1 0

21
misc/m5a10/code.py Normal file
View File

@@ -0,0 +1,21 @@
a, b = input().split()
map_a = {}
map_b = {}
for i in range(len(a)):
if a[i] in map_a:
if (b[i] != map_a[a[i]]):
print('false')
break
else:
map_a[a[i]] = b[i]
if b[i] in map_b:
if (a[i] != map_b[b[i]]):
print('false')
break
else:
map_b[b[i]] = a[i]
else:
print('true')

1
misc/m5a10/input Normal file
View File

@@ -0,0 +1 @@
show same

20
misc/mysterious/bai1.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("bai1.inp", "r", stdin);
int min_gcd, n;
cin >> n >> min_gcd;
n--;
int prod = n;
while (n--) {
int x;
cin >> x;
min_gcd = lcm(min_gcd, x);
}
cout << min_gcd << '\n';
}

2
misc/mysterious/bai1.inp Normal file
View File

@@ -0,0 +1,2 @@
3
4 2 8

0
misc/mysterious/bai2.cpp Normal file
View File

1
misc/mysterious/bai2.inp Normal file
View File

@@ -0,0 +1 @@
abc3456789PQ

0
misc/mysterious/cpp.cpp Normal file
View File

BIN
misc/mysterious/cpp.out Executable file

Binary file not shown.

0
misc/mysterious/nhap Normal file
View File

37
misc/mysterious/tgc.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
int a[500000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("tgc.inp", "r", stdin);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int res = 0;
for (int i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1])
continue;
int l = i, r = n - 1;
int mid;
while (l < r) {
mid = (l + r) / 2;
if (a[mid] < 2 * a[i]) {
l = mid + 1;
} else {
r = mid;
}
}
res += r - mid + l;
}
cout << res << "\n";
}

2
misc/mysterious/tgc.inp Normal file
View File

@@ -0,0 +1,2 @@
8
5 3 2 9 5 4 9 5

22
misc/others/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug C++ (input.inp)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": ["<", "${fileBasenameNoExtension}.inp"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build C++",
"MIMode": "gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty printing",
"text": "-enable-pretty-printing"
}
]
}
]
}

22
misc/others/.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build C++",
"type": "shell",
"command": "g++",
"args": [
"-std=gnu++17",
"-O0",
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

BIN
misc/others/a.out Executable file

Binary file not shown.

BIN
misc/others/a.out.conflict1 Normal file

Binary file not shown.

BIN
misc/others/b.out Executable file

Binary file not shown.

BIN
misc/others/beauty Executable file

Binary file not shown.

66
misc/others/beauty.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include <bits/stdc++.h>
using namespace std;
const int maxc = 50000;
char check[maxc + 1];
vector<int> prime;
void sieve() {
for (int i = 0; i < maxc; i++)
check[i] = 1;
check[0] = 0;
check[1] = 0;
for (int i = 2; i * i < maxc; i++)
if (check[i])
for (int j = i * i; j < maxc; j += i)
check[j] = 0;
for (int i = 2; i < maxc; i++) {
if (check[i])
prime.push_back(i);
}
}
int is_db(int n) {
int m = n;
vector<int> factor;
for (int i = 0; i < prime.size() && prime[i]*prime[i]<=n;i++) {
while (n % prime[i] == 0) {
factor.push_back(prime[i]);
n /= prime[i];
}
}
factor.push_back(n);
int facsum = 0;
for (auto i : factor) {
while (i) {
facsum += i % 10;
i /= 10;
}
}
int sum = 0;
while (m) {
sum += m % 10;
m /= 10;
}
if (sum == facsum) {
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
n++;
sieve();
while (!is_db(n)) {
n++;
}
cout << n << "\n";
}

1
misc/others/beauty.inp Normal file
View File

@@ -0,0 +1 @@
21

BIN
misc/others/lares Executable file

Binary file not shown.

30
misc/others/lares.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
int m, n, k;
int check(int _x) {
int mn = _x * 2;
int nn = _x;
if (mn < 0 || nn < 0 || m - mn + n - nn < k) {
return 0;
}
return 1;
}
int main() {
cin >> m >> n >> k;
int l = 0, r = min(m / 2, n);
int res = 0;
while (l < r) {
int mid = (l + r) / 2;
if (check(mid)) {
res = max(res, mid);
l = mid + 1;
} else {
r = mid;
}
}
cout << res << '\n';
}

1
misc/others/lares.inp Normal file
View File

@@ -0,0 +1 @@
12 7 5

63
misc/others/other.cpp Normal file
View File

@@ -0,0 +1,63 @@
#include <cmath>
#include <iostream>
using namespace std;
bool isComposite(int n) {
if (n <= 1) {
return false;
}
if (n <= 3) {
return false;
}
if (n % 2 == 0 || n % 3 == 0) {
return true;
}
int i = 5;
while (i * i <= n) {
if (n % i == 0 || n % (i + 2) == 0) {
return true;
}
i = i + 6;
}
return false;
}
int getSum(int n) {
int s = 0;
while (n > 0) {
s += n % 10;
n /= 10;
}
return s;
}
int getPrimeSum(int n) {
int s = 0;
while (n % 2 == 0) {
s += 2;
n /= 2;
}
for (int i = 3; i <= sqrt(n); i += 2) {
while (n % i == 0) {
s += getSum(i);
n /= i;
}
}
if (n > 2) {
s += getSum(n);
}
return s;
}
int main() {
int n;
cin >> n;
while (true) {
if (getSum(n) == getPrimeSum(n)) {
if (getPrimeSum(n) != 0) {
if (isComposite(n)) {
break;
}
}
}
n += 1;
}
cout << n << endl;
return 0;
}

11
misc/python.py Normal file
View File

@@ -0,0 +1,11 @@
x = int(input())
y = int(input())
counter = 0
while (x or y):
counter += (x % 2)^(y % 2)
x >>= 1
y >>= 1
print(counter)

18
misc/so_mu_dung/code.py Normal file
View File

@@ -0,0 +1,18 @@
import math
highest_num = [0]*31
a = [int(_) for _ in input().split()]
for i in a:
for k in range(32, 0, -1):
if (i % 2**k == 0):
highest_num[k] += 1
res = 0
for i in highest_num:
if (i <= 1):
continue
res += math.comb(i, 2)
print(res)

BIN
misc/tlbdhsg/a.out Executable file

Binary file not shown.

25
misc/tlbdhsg/b19.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unordered_set<int> hash;
deque<int> res;
while (n--) {
int x;
cin >> x;
if (hash.find(x) == hash.end()) {
res.push_back(x);
hash.insert(x);
}
}
cout << res.size() << '\n';
while (!res.empty()) {
cout << res.front() << " ";
res.pop_front();
}
cout << '\n';
}

22
misc/tlbdhsg/b20.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x, k;
cin >> n >> k >> x;
cout << n + 1 << '\n';
k--;
while (n--) {
int a;
cin >> a;
cout << a << ' ';
k--;
if (!k)
cout << x << ' ';
}
cout << '\n';
}

4
misc/tlbdhsg/ginny.cpp Normal file
View File

@@ -0,0 +1,4 @@
#include <bits/stdc++.h>
using namespace std;
int main() {}

20
misc/tlbdhsg/stones.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a = sqrt(n);
int b = (n + a - 1) / a;
int res_a = a, res_b = b;
a += 1;
b = (n + a - 1) / a;
if (a + b < res_a + res_b) {
cout << a << " " << b << "\n";
} else {
cout << res_a << " " << res_b << "\n";
}
}

31
misc/tlbdhsg/stones_t.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
long long n;
if (!(cin >> n))
return 0;
// The minimum sum a+b for a*b >= n occurs when a and b are close to sqrt(n)
long long a = sqrt(n);
long long b = (n + a - 1) / a; // Ceiling division
// We check if (a+1) provides a better sum
// though mathematically, the first integer b near sqrt(n) is usually it.
long long res_a = a, res_b = b;
// Check the neighbor just in case of rounding issues with sqrt
long long a2 = a + 1;
long long b2 = (n + a2 - 1) / a2;
if (a2 + b2 < res_a + res_b) {
res_a = a2;
res_b = b2;
}
cout << res_a << " " << res_b << endl;
return 0;
}

BIN
misc/w5a8.a Executable file

Binary file not shown.

16
misc/w5a8.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b; cin >> a >> b;
int ans = 0;
while (a or b) {
cout << "value: " << a % 2 << " " << b % 2 << "\n";
ans += (int)(((a % 2) ^ (b % 2)));
a >>= 1;
b >>= 1;
}
cout << ans << '\n';
}