A. Simple Palindrome (贪心)
题意:
NarekNarekNarek需要制作一个仅由元音组成的字符串。制作完字符串后,他会要求孩子们计算回文子序列的数量。NarekNarekNarek希望保持简单,所以他正在寻找一个字符串,使得回文子序列的数量最少。 帮助 NarekNarekNarek找到一个长度为 nnn的字符串,该字符串仅由小写英语元音组成(字母 a\mathtt{a}a、 e\mathtt{e}e、 i\mathtt{i}i、 o\mathtt{o}o和 u\mathtt{u}u),从而最小化字符串中的回文子序列数量。
分析:
我们以aeiouaeiouaeiou为一组,如果再考虑插入一个新字符,可以发现所有相同字符排在一起才是最优,例如aaeiouaaeiouaaeiou。而对于每个字符数量则以尽可能均分为最优。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int N = 3e5 + 10;
const int InF = 2e9 + 5;
const int mod = 1e9 + 7;
string s = "aeiou";
int a[5];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string ans;
memset(a, 0, sizeof(a));
for (int i = 0; i < n % 5; i++)
{
a[i]++;
}
for (int i = 0; i < 5; i++)
{
a[i] += n / 5;
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < a[i]; j++)
{
ans += s[i];
}
}
cout << ans << endl;
}
return 0;
}
B2.The Strict Teacher (Hard Version) (二分)
题意:
现在有mmm名老师一起追捕DavidDavidDavid。幸运的是,教室很大,所以DavidDavidDavid有很多地方可以躲藏。教室可以表示为一条线,单元格从 111到 nnn。 开始时,所有 mmm名老师和DavidDavidDavid都在不同的单元格中。然后他们开始行动。每次行动时
-
DavidDavidDavid会前往相邻的单元格或留在当前单元格。
-
每位 mmm老师同时前往相邻的单元格或留在当前单元格。
这种情况会一直持续到DavidDavidDavid被抓住。如果任何一位老师(可能不止一位)与 DavidDavidDavid位于同一个单元格,DavidDavidDavid就会被抓住。每个人都能看到其他人的动作,因此他们都采取了最佳行动。 你的任务是找出如果老师们都采取最佳行动,他们需要多少步才能抓住DavidDavidDavid。
分析:
分情况讨论,如果DavidDavidDavid被老师夹在中间,假设两位老师之间有kkk个空位,那么DavidDavidDavid能活⌈k2⌉\lceil \frac{k}{2} \rceil⌈2k⌉轮。我们可以对bbb排序后用lowerboundlowerboundlowerbound找到DavidDavidDavid左右的老师。 如果DavidDavidDavid没有被老师夹住:那么DaivdDaivdDaivd显然会贪心地往边界跑,那么只需要求出离他最近的老师xxx的位置即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int N = 3e5 + 10;
const int InF = 2e9 + 5;
const int mod = 1e9 + 7;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n, m, q;
cin >> n >> m >> q;
vector<int> b(m);
for (int &x : b)
cin >> x;
sort(begin(b), end(b));

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



