2024.12.11 周三
2024.12.11 周三
Q1. 1100
给定一长度为 \(n\) 的数组,你需要执行 \(k\) 次操作:每次选择一连续子数组(可为空),将和作为一元素放到到数组的任意位置。问最后数组和的最大值。
Q2. 1100
给你一长度为\(2n\)的数组\(a\),\(1\)~\(n\)各出现2次。让你找出两个大小为\(2k\)集合\(l\),\(r\),其中\(l\)属于\(a\)1至\(a\)n,\(r\)属于\(a\)n+1至\(a\)2n。满足\(l\)异或和等于\(r\)异或和。
Q3. 1000
Rudolf has an array \(a\) of \(n\) integers.
In one operation, he can choose an index \(i\) (\(2 \le i \le n - 1\)) and assign:
- \(a_{i - 1} = a_{i - 1} - 1\)
- \(a_i = a_i - 2\)
- \(a_{i + 1} = a_{i + 1} - 1\)
Rudolf can apply this operation any number of times. Any index \(i\) can be used zero or more times.
Can he make all the elements of the array equal to zero using this operation?
Q4. 1100
给你一长度为\(n\)的数组,\(x\)为0,\(i\):1~n,找到大于\(x\)且为\(a\)i倍数的数,更新\(x\)。
------------------------独自思考分割线------------------------
A1. 2点
1.第一次操作必然是选择最大连续子数组,然后将其放到最大连续子数组内。
2.以后的操作就可以看作最大和一变二,二变四的过程。
A2. 2点
1.发现\(a\)1至\(a\)n这一侧单独出现的数字与右侧相同。
2.同时出现\(2\)次的数异或和为0。可以先使用出现\(2\)次的数构造,不够再使用单次出现的数构造。
A3. 1点
1.遍历贪心去减,不够减/最后没减为0则NO
A4. 2点
1.快速找到大于\(x\)的\(a\)i的倍数,直接枚举显然不可行。二分当然可以。
2.数学当然ok,\(k\)\(a\)i>x,=>\(k\)>=\(x\)/\(a\)i,==>k=\(x\)/\(a\)i+1,取整的时候注意一下,答案就是\(k\)\(a\)i。
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
const int mod = 1e9 + 7;
int qm(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1)
res = res * a % mod; // 不要取模时记得取消
a = a * a % mod;
b >>= 1;
}
return res;
}
int inv(int n)
{
return qm(n, mod - 2);
}
void _()
{
int n, k;
cin >> n >> k;
int pre = 0, min_pre = 0, max_rangesum = 0;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
pre += x;
max_rangesum = max(max_rangesum, pre - min_pre);
min_pre = min(min_pre, pre);
}
int res = (max_rangesum % mod * qm(2, k)) % mod;
res = (res + pre % mod - max_rangesum % mod + (int)(1e7) * mod) % mod;
cout << res << endl;
}
A2.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, k;
cin >> n >> k;
vector<int> l(n + 1);
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
l[x]++;
}
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
}
set<int> db_l, db_r, sgal;
for (int i = 1; i <= n; i++)
if (!l[i])
db_r.insert(i);
else if (l[i] == 1)
sgal.insert(i);
else
db_l.insert(i);
vector<int> res_l, res_r;
auto get = [&](vector<int> &res, set<int> &l)
{
for (auto x : l)
if (res.size() < k << 1)
res.push_back(x), res.push_back(x);
for (auto x : sgal)
if (res.size() < k << 1)
res.push_back(x);
};
get(res_l, db_l);
get(res_r, db_r);
for (auto v : res_l)
cout << v << ' ';
cout << endl;
for (auto v : res_r)
cout << v << ' ';
cout << endl;
}
A3.
#include <bits/stdc++.h>
#define int long long //
// #define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int f = 1;
for (int i = 1; i + 2 <= n; i++)
{
if (a[i + 1] < a[i] << 1 || a[i + 2] < a[i])
f = 0;
a[i + 1] -= a[i] << 1;
a[i + 2] -= a[i];
}
if (a[n - 1] || a[n])
f = 0;
cout << (f ? "YES" : "NO") << endl;
}
A4.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
int x;
cin >> x;
int res = x;
for (int i = 2; i <= n; i++)
{
cin >> x;
int k = res / x + 1;
res = x * k;
}
cout << res << endl;
}

浙公网安备 33010602011771号