'commit'
This commit is contained in:
BIN
GESP/Level5/GESP202409/2024 年 09 ⽉.pdf
Normal file
BIN
GESP/Level5/GESP202409/2024 年 09 ⽉.pdf
Normal file
Binary file not shown.
30
GESP/Level5/GESP202409/20240901.cpp
Normal file
30
GESP/Level5/GESP202409/20240901.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1e5 + 10;
|
||||
int a[N], c[N];
|
||||
/*
|
||||
2 2
|
||||
9 9
|
||||
1 -1
|
||||
|
||||
参考答案:10
|
||||
*/
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
int mx = -1e9;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> c[i];
|
||||
mx = max(mx, c[i]);
|
||||
}
|
||||
for (int i = 1; i <= m; i++)
|
||||
cin >> a[i];
|
||||
|
||||
for (int i = 1; i <= m;i++) { // 注意特殊情况,比如n=1,此时如果a[i]<0,那么就只能是减掉
|
||||
if (n == 1 || a[i] > 0)
|
||||
mx += a[i];
|
||||
}
|
||||
cout << mx << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
71
GESP/Level5/GESP202409/20240902.cpp
Normal file
71
GESP/Level5/GESP202409/20240902.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
// 欧拉筛
|
||||
const int N = 1e5 + 10;
|
||||
int primes[N], cnt; // primes[]存储所有素数
|
||||
bool st[N]; // st[x]存储x是否被筛掉
|
||||
void get_primes(int n) {
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (!st[i])
|
||||
primes[cnt++] = i;
|
||||
for (int j = 0; primes[j] * i <= n; j++) {
|
||||
st[primes[j] * i] = true;
|
||||
if (i % primes[j] == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
3
|
||||
6 188 9999
|
||||
|
||||
参考答案
|
||||
2
|
||||
4
|
||||
-1
|
||||
*/
|
||||
|
||||
int main() {
|
||||
get_primes(N);
|
||||
|
||||
int T;
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
|
||||
int h;
|
||||
cin >> h;
|
||||
// 如果h质数,则一次魔法攻击就可以解决问题,答案是1,continue表示本组测试用例处理完成
|
||||
if (!st[h]) {
|
||||
cout << 1 << endl;
|
||||
continue;
|
||||
}
|
||||
// 如果没有干掉,需要找到最大的质数扣除掉
|
||||
int mx = 0;
|
||||
for (int i = 0;; i++) {
|
||||
if (primes[i] > h)
|
||||
break;
|
||||
else
|
||||
mx = max(mx, primes[i]);
|
||||
}
|
||||
// 扣除掉最大质数
|
||||
h -= mx;
|
||||
|
||||
int ans = 1;
|
||||
// 开始物理攻击
|
||||
int base = 1;
|
||||
for (int i = 1;; i++) {
|
||||
ans++;
|
||||
h -= base;
|
||||
if (h < 0) {
|
||||
cout << -1 << endl;
|
||||
break;
|
||||
}
|
||||
if (h == 0) {
|
||||
cout << ans << endl;
|
||||
break;
|
||||
}
|
||||
base *= 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user