This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

Binary file not shown.

View File

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

View File

@@ -0,0 +1,12 @@
16 11
1
2
4
8
16
32
64
128
256
512
1024

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
set<int> s; // 幸运数集合
const int N = 1e6;
int main() {
int a, T;
cin >> a >> T;
// 筛法,枚举出1e6以下所有的超级幸运数
for (int i = 1; i * i <= N; i++)
if (i * i >= a) {
// 枚举超级幸运数的倍数
for (int j = 1; i * i * j <= N; j++)
s.insert(i * i * j);
}
while (T--) {
int x;
cin >> x;
// 判断x是不是超级幸运数或者幸运数
if (s.count(x))
cout << "Lucky" << endl;
else {
// 找出第一个比它大的幸运数
for (int i = x + 1;; i++)
if (s.count(i)) {
cout << i << endl;
break;
}
}
}
return 0;
}

View File

@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int a[N];
int ans;
/*
3
1 2 3
答案:2
5
5 6 2 10 13
答案:
8
*/
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
// 很明显,1e6的平方级算法会TLE,但40%的测试点是可以过的
set<int> s; // 哪个数字已经被淘汰掉了
for (int i = 31; i >= 0; i--) {
int cnt = 0;
for (int j = 1; j <= n; j++) { // 遍历所有数字
if (s.count(j) == 0 &&
a[j] >> i & 1) // 如果a[j]这个数字没有被淘汰掉,并且这个数字的第i位是1
cnt++;
}
if (cnt >= 2) {
// 如果此位存在1两个以上,那么此位是有效数位,所以此位是0的会被淘汰
for (int j = 1; j <= n; j++)
if (!(a[j] >> i & 1))
s.insert(j);
// 记录&的累加值
ans = ans + (1 << i);
}
}
cout << ans << endl;
return 0;
}

View File

@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int a[N];
int ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
set<int> _set; // 哪个数字已经被淘汰掉了
for (int i = 30; i >= 0; i--) {
int cnt = 0; // 枚举每个数字的二进制数位,由高到低
for (int j = 1; j <= n; j++) {
if (a[j] >> i & 1 && !_set.count(j))
cnt++;
}
if (cnt >= 2) {
for (int j = 1; j <= n; j++)
if (!(a[j] >> i & 1))
_set.insert(j);
ans = ans + (1 << i);
}
}
cout << ans << endl;
return 0;
}