Codeforces Round #809 (Div. 2)

目录

A. Another String Minimization Problem

B. Making Towers

C. Qpwoeirut And The City


A. Another String Minimization Problem

A. Another String Minimization Problem

思路:

模拟

代码如下:

#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false), cin.tie(nullptr); cout.tie(nullptr)

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e5 + 10, M = 110;
const int mod = 998244353;

int T;

void solve()
{
    int n, m;
    string s;
    cin >> n >> m;
    
    
    int a[N];
    for(int i = 1; i <= n; i ++ )
        cin >> a[i];
        
    s += ' ';
    for(int i = 0; i < m; i ++ )
        s += "B";
    
    sort(a + 1,  a + n + 1);
    
    for(int i = 1; i <= n; i ++ )
        if(s[min(a[i], m - a[i] + 1)] == 'B') s[min(a[i], m - a[i] + 1)] = 'A'; 
        else s[max(a[i], m - a[i] + 1)] = 'A';
       
    //cout << s << endl;
    for(int i = 1; i <= m; i ++ )
        cout << s[i];
    cout << endl;
}

int main()
{
    fast;
    cin >> T;
    while(T -- )
        solve();
    
    return 0;
}
 

B. Making Towers

B. Making Towers

思路:

只要相同的数字的两者相距为奇数,两者即可叠在一起

代码如下:

#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false), cin.tie(nullptr); cout.tie(nullptr)

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e5 + 10, M = 110;
const int mod = 998244353;

int T;

void solve()
{
    int n, m;
    string s;
    cin >> n;
    
    map<int, PII> mp;
    int a[N];
    for(int i = 1; i <= n; i ++ )
    {
        cin >> a[i];
        if(mp[a[i]].y == 0) mp[a[i]] = {i, 1};
        else 
        {
            if((i - mp[a[i]].x) % 2)
            {
                mp[a[i]].x = i;
                mp[a[i]].y += 1;
            }
                
        }
    }
    
    for(int i = 1; i <= n; i ++ )
        cout << mp[i].y << " ";
    cout << endl;
    
}

int main()
{
    fast;
    cin >> T;
    while(T -- )
        solve();
    
    return 0;
}
 

C. Qpwoeirut And The City

C. Qpwoeirut And The City

思路:

两种情况:

总数为奇数时,一定为每个偶数楼层为cool,所以求出将所有的偶数位置成立的最小值

总数为偶数时,

在任意的偶数位置,可在该偶数的右侧选择一个奇数位置,此后所选都是奇数位置,即

选择 一部分偶数位置 + 一部分奇数位置,(其中,偶数位置和奇数位置都可以为0,变成全偶数,或全奇数位置状态)

代码如下:

#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false), cin.tie(nullptr); cout.tie(nullptr)

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 2e5 + 10, M = 110;
const int mod = 998244353;

int T;

void solve()
{
    int n, m;

    cin >> n;
    
    LL a[N];
    for(int i = 1; i <= n; i ++ )
        cin >> a[i];
        
    if(n % 2)
    {
        LL res = 0;
        for(int i = 2; i <= n; i += 2 )
        {
            if(max(a[i - 1], a[i + 1]) >= a[i])
                res += max(a[i - 1], a[i + 1]) + 1 - a[i];
        }
        cout << res << endl;
    }
    else 
    {
        LL s[N];
        s[0] = 0, s[n] = 0;
        for(int i = 2; i < n; i ++ )
            if(max(a[i - 1], a[i + 1]) >= a[i]) s[i] = max(a[i - 1], a[i + 1]) + 1 - a[i];
            else s[i] = 0;
        
        s[0] = 0, s[1] = 0;
        for(int i = 2; i <= n; i ++ )
            if(i % 2) s[i] = s[i - 2] + s[i];
            else s[i] = s[i - 2] + s[i];
        
        LL res = 0;
        res = min(s[n - 1], s[n]);
        
        for(int i = 2; i <= n - 2; i += 2 )
            res = min(res, s[i] +  s[n - 1] - s[i + 1]);

        cout << res << endl;
    }
    
    
}

int main()
{
    fast;
    cin >> T;
    while(T -- )
        solve();
    
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AC自动寄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值