2022.3.28

2022/3/28 6:22:40

本文主要是介绍2022.3.28,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Codeforces Round #779 (Div. 2)

A. Marin and Photoshoot

把所有0的位置找出来放到数组里,如果相邻的0距离为1的话,说明要往中间插2个1,如果距离为2的话只需要插1个1。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=2e5+10,INF=1e8;
int a[N];
int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin >> n;
        string s;
        cin >> s;
        int cnt = 0,ans=0;
        for (int i = 0; i < s.size();i++)
        {
            if(s[i]=='0')
                a[cnt++] = i;
        }
        for (int i = 0; i < cnt-1;i++)
        {
            if(abs(a[i]-a[i+1])==1)
            {
                ans+=2;
            }
            else if(abs(a[i]-a[i+1])==2)
            {
                ans ++;
            }
        }
            cout << ans << '\n';
    }
    return 0;
}

B. Marin and Anti-coprime Permutation

为了满足条件,需要把奇数的位置放偶数,偶数的位置放奇数,这样乘起来每个位置一定是偶数,那么最大公约数必不可能为1。放位置的就是排列组合,把n/2,即偶数和奇数的位置的个数,然后分别全排列最后在相乘。当n为奇数一定不满足,因为奇数和偶数的位置个数不一样。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=2e5+10,INF=1e8,mod=998244353;
int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin >> n;
        if(n&1)
            cout << 0 << '\n';
        else
        {
            int k = n / 2;
            ll ans = 1;
            for (int i = 1; i <= k;i++)
            {
                ans = ans * i % mod;
            }
            ans = ans * ans % mod;
            cout << ans << '\n';
        }
    }
    return 0;
}

C. Shinju and the Lost Permutation



这篇关于2022.3.28的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程