A
。
#include "bits/stdc++.h"
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int s, s1, s2, s3;
cin >> s >> s1 >> s2 >> s3;
cout << (s < 425 && min({s1, s2, s3}) < 60 ? "YES" : "NO") << '\n';
return 0;
}
B
。
#include "bits/stdc++.h"
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end(), [&](int x, int y) {
if (x % 2 != y % 2) {
return x % 2 < y % 2;
}
return x < y;
});
for (int i = 0; i < n; i++) {
cout << a[i] << " \n"[i == n - 1];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
C
与数组无关,答案为 。
。
#include "bits/stdc++.h"
using namespace std;
using i64 = int64_t;
constexpr int P = 998244353;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
i64 ans = 1;
for (int i = 1; i < n; i++) {
ans = ans * 2 % P;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
D
考虑奇数的情况,序列中只要存在一个偶数即可,记奇数数量为 ,答案为
。
。
#include "bits/stdc++.h"
using namespace std;
using i64 = int64_t;
constexpr int P = 998244353;
void solve() {
int n;
cin >> n;
i64 ans0 = 1, ans1 = 1;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % 2) {
ans1 = ans1 * 2 % P;
}
ans0 = ans0 * 2 % P;
}
cout << (ans0 - ans1 + P) % P << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
E
总和不变,对原数组求和,记总和为 ,问题变为最多能将
分成几个有趣的数。
预处理有趣的数, 表示
是否可以分成
个有趣的数的和,这里用了
优化,若无法将
分成
个有趣的数,则先分出
个
。
记有趣的数的数量为 。
。
#include "bits/stdc++.h"
using namespace std;
bitset<20001> f[101];
vector<int> num;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = accumulate(a.begin(), a.end(), 0);
cout << (f[n][sum] ? n : n - 1) << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 1; i * i < 20001; i++) {
string s = to_string(i * i);
int sum = 0;
for (auto c : s) {
sum += c - '0';
}
int q = sqrt(sum);
if (q * q == sum) {
num.push_back(i * i);
}
}
f[0][0] = 1;
for (int i = 0; i < 100; i++) {
for (auto x : num) {
f[i + 1] |= f[i] << x;
}
}
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}