Codeforces Round #779 (Div. 2)

 原题链接:

Dashboard - Codeforces Round #779 (Div. 2) - Codeforceshttps://codeforces.com/contest/1658


 A. Marin and Photoshoot

思路:

当0连续出现两次,可以加入两个1。

例如:000,可变成:0110110。

可能会出现0出现两次,但是已经有了一个1,那么就加入一个1。

例如:01010,可变成:0110110。

10,01的情况都不满足。

例如:100110101,可变成:101101101101。

代码:

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 1e3 + 5;

void solve()
{
    int n;
    char s[105];
    cin >> n >> s;
    int res = 0;
    for(int i = 0; i < n; i ++)
    {
        if(s[i] == '0' && s[i + 1] == '0') res += 2;
        if(s[i] == '0' && s[i + 1] == '1' && s[i + 2] == '0') res ++;
    }
    cout << res << '\n';
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    
    int t;
    cin >> t;
    while(t --) solve();
}


 B. Marin and Anti-coprime Permutation

思路:

看样例,不难猜到n为奇数时,没有满足题意的{1,2,3 ... ,n}的任意全排列,答案为0。

对于gcd{1×p1,2×p2,3×p3,... ,n×pn},他们的公共最大公因数要大于1, 全部匹配成偶数那么他们gcd结果为2,2>1满足题意。

当n为奇数时,有(n-1)/2个偶数,(n+1)/2个奇数,奇数比偶数多1个,不可能全部配成偶数。

奇数×偶数=偶数

当n = 6,那么1,3,5这3个位置可以乘上2,4,6这3个数,则2,4,6这3个位置可以乘上1,3,5这3个数。

排列组合有A3 3 * A3 3,为3*2*1 * 3*2*1 ,即36种。

当n = 1000, 那么1,3,5,7,...,n - 1这500个位置可以 乘上2,4,...,n这500个数,同理。

排列组合为A500 500 * A500 500,即500 * 499 *...* 2 * 1 * 500 * 499 *...* 2 * 1种为答案。

代码:

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 998244353;

void solve()
{
    int n;
    cin >> n;
    if(n % 2 == 1)
    {
        cout << 0 << '\n';
        return;
    }
    else
    {
        int t = n / 2;
        int res = 1;
        while(t > 0)
        {
            res *= t;
            res %= N;
            res *= t;
            res %= N;
            t --;
        }
        cout << res << '\n';
    }
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    
    int t;
    cin >> t;
    while(t --) solve();
}


 C. Shinju and the Lost Permutation

思路:

问题给出一个有n个元素的数组c,c中元素表示自己构造的数组p的power值,数组p可以不断滑动一位产生新的不同的power值,p为{1,2,3,...,n}的任意排列。

可知数组c中肯定有一元素为1,而且1只会出现一次,因为数组p可滑动为最大数n在第一位的排列,则power为1。

通过样例观察和自己列式,每次数组p滑动,power只会增加1,因为只可能是一个较小数滑动到第一位power才会增加。而power可以减少不只1,因为可能是一个大数滑动到第一位。

例如:①p={3,5,1,2,4,6}  b={3,5,5,5,5,6} power = 3.

           ②p={6,3,5,1,2,4} b={6,6,6,6,6,6} powert = 1.

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 1e5 + 5;
int a[N];

void solve()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++) cin >> a[i];
    
    int flag = 0;
    for(int i = 0; i < n; i ++)
    {
        if(a[i] == 1) flag ++;
    }
    
    if(flag != 1)
    {
        cout << "NO\n";
    }
    else
    {
        for(int i = 1; i < n; i ++)
        {
            if(a[i] - a[i - 1] > 1)
            {
                cout << "NO\n";
                return;
            }
        }
        if(a[0] - a[n - 1] > 1)
        {
            cout << "NO\n";
            return;
        }
        cout << "YES\n";
    }
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    
    int t;
    cin >> t;
    while(t --) solve();
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值