Codeforces Round 972 (Div. 2) A~E

A. Simple Palindrome (贪心)

题意:

NarekNarekNarek需要制作一个仅由元音组成的字符串。制作完字符串后,他会要求孩子们计算回文子序列的数量。NarekNarekNarek希望保持简单,所以他正在寻找一个字符串,使得回文子序列的数量最少。 帮助 NarekNarekNarek找到一个长度为 nnn的字符串,该字符串仅由小写英语元音组成(字母 a\mathtt{a}ae\mathtt{e}ei\mathtt{i}io\mathtt{o}ou\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有很多地方可以躲藏。教室可以表示为一条线,单元格从 111nnn。 开始时,所有 mmm名老师和DavidDavidDavid都在不同的单元格中。然后他们开始行动。每次行动时

  • DavidDavidDavid会前往相邻的单元格或留在当前单元格。

  • 每位 mmm老师同时前往相邻的单元格或留在当前单元格。

这种情况会一直持续到DavidDavidDavid被抓住。如果任何一位老师(可能不止一位)与 DavidDavidDavid位于同一个单元格,DavidDavidDavid就会被抓住。每个人都能看到其他人的动作,因此他们都采取了最佳行动。 你的任务是找出如果老师们都采取最佳行动,他们需要多少步才能抓住DavidDavidDavid

分析:

分情况讨论,如果DavidDavidDavid被老师夹在中间,假设两位老师之间有kkk个空位,那么DavidDavidDavid能活⌈k2⌉\lceil \frac{k}{2} \rceil2k轮。我们可以对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));
        
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值