2024.12.17 周二
2024.12.17 周二
Q1. 1000
Jonathan is fighting against minions. There are
Denote
Here,
Jonathan will divide the vampires into contiguous groups, such that each vampire is in exactly one group, and the sum of strengths of the groups is minimized. Among all ways to divide the vampires, he would like to find the way with the maximum number of groups.
Given the strengths of each of the
Q2. 1000
You are given a positive integer
In this problem, the
The primality of an array
Find any permutation of
Q3. 1000
The array
Note that any array consisting of zero elements or one element is beautiful.
You are given an array
- if you can append the integer
to the back of the array so that the array stays beautiful, you have to append it; - otherwise, do nothing.
After each query, report whether you appended the given integer
Q4. 1000
Dima Vatrushin is a math teacher at school. He was sent on vacation for
You are given an array
Dima was born in Siberia, so he can go on vacation only if the temperature does not rise above
Unfortunately, Dima was so absorbed in abstract algebra that he forgot how to count. He asks you to help him and count the number of ways to choose vacation dates at the resort.
Q5, 1000
You are given a string
Let's say that the binary string (a string where each character is either 0 or 1) matches the pattern if you can replace each character ? with 0 or 1 (for each character, the choice is independent) so that the strings become equal. For example, 0010 matches ?01?, but 010 doesn't match 1??, ??, or ????.
Let's define the cost of the binary string as the minimum number of operations of the form "reverse an arbitrary contiguous substring of the string" required to sort the string in non-descending order.
You have to find a binary string with the minimum possible cost among those that match the given pattern. If there are multiple answers, print any of them.
------------------------独自思考分割线------------------------
-
Q1较难,Q2二十分钟,Q3wa3发,Q4Q5都是十分钟顺切。
A1.
- 昨天被卡了,这次花了半小时过了。是道好题,不得不说,做位运算主要靠运算符的性质进行思考,需要很熟悉操作符或者时刻想着它。
- 发现最小值一定是f(1,n),再考虑如何在最小值情况下分出最多的连续块。
- 如果最小值非0,设为1101,那么每个块的每个元素都必须含1101,不然
和不可能为1101。这样块和一定不会为1101。因此不能分块。 - 最小值为0的话,贪心去分 0 0 0 ..。考虑2点:1.不可能出现0 1 0的情况,2.不能正好分块,最后的一部分合并在最后一块即可。
A2.
- 1是特殊的数,如果一个集合不包含1必定无贡献,包含1并且无2一定有贡献,包含1 2不含3一定有贡献。
- 考虑 2... 1...3 ,则可以构造出的贡献左侧选择的方案数*右侧选择的方案数,若n+1不是质数则-1。
- 构造真是有依据地进行天马行空。
A3.
- 其实就是分类进行模拟,
值域考虑不完善wa了3发。
A4.
- 找到每个合法的连续子段,考虑双指针(注意细节),保存长度。
- 对于每个合法长度,等差数列公式求方案数。
A5
- 算是一道构造,只要不增加连续1的段数就不会增加代价,同时改1可能会连接减少段数。
- 讨论各种情况后发现,
只需要复制前面的即可。
------------------------代码分割线------------------------
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;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int ans = a[1];
for (int i = 2; i <= n; i++)
ans &= a[i];
if (ans)
{
cout << 1 << endl;
return;
}
int res = 0;
for (int i = 1; i <= n; i++)
{
int t = a[i];
if (!t)
{
res++;
continue;
}
int j = i + 1;
for (; j <= n; j++)
{
t &= a[j];
if (!t)
break;
}
// bug(j);
if (j <= n)
res++, j++;
i = j - 1;
}
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;
cin >> n;
vector<int> l, r;
if (n > 1)
l.push_back(2);
int f = 1;
for (int i = 4; i <= n; i++)
if (f)
l.push_back(i), f ^= 1;
else
r.push_back(i), f ^= 1;
l.push_back(1);
if (n > 2)
r.push_back(3);
auto output = [](vector<int> &t)
{
for (auto v : t)
cout << v << ' ';
};
output(l);
output(r);
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 = 0; i < n; i++)
cin >> a[i];
int pre = a[0], las = a[1];
int f = pre > las;
string res = "11";
for (int i = 2; i < n; i++)
{
int x = a[i];
bool has = 0;
if (!f)
{
if (x >= las || x <= pre) // 这里不判断确实思路不够完善 考虑整个值域
{
has = 1;
if (x < las)
f = 1;
}
}
else if (x <= pre && x >= las)
has = 1;
res += has ? '1' : '0';
if (has)
las = x;
}
if (n == 1)
res = '1';
cout << res << 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, k, q;
cin >> n >> k >> q;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<int> t;
for (int i = 1; i <= n; i++)
if (a[i] <= q)
{
int j = i;
for (; j <= n && a[j] <= q; j++)
;
t.push_back(j - i);
i = j - 1;
}
auto get = [k](int x)
{
return x < k ? 0 : (x - k + 1) * (x - k + 2) >> 1;
};
int res = 0;
for (auto v : t)
res += get(v); //, bug(v);
cout << res << endl;
}
A5
#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 _()
{
string s;
cin >> s;
if (s.front() == '?')
s[0] = '0';
for (int i = 1; i < s.size(); i++)
if (s[i] == '?')
s[i] = s[i - 1];
cout << s << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!