Codeforces Round #779 (Div. 2)

A.题意就是在0和0之间至少有2个1,如果不满足条件,就插入1,计算插入1的个数。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;

void solve() {
    int n;
    scanf("%d", &n);
    string str;
    cin >> str;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (str[i] == '0' && str[i - 1] == '0') {
            ans += 2;
        }
        if (i - 2 >= 0 && str[i] == '0' && str[i - 1] == '1' && str[i - 2] == '0') {
            ans += 1;
        }
    }
    printf("%d\n", ans);
}

int main(int argc, char** argv) {
    int _t;
    scanf("%d", &_t);
    while (_t--) {
        solve();
    }
    return 0;
}

B.题意大概为:用n构建一个数组p1,p2,…,pn,使数组满足gcd(1⋅p1,2⋅p2,…,n⋅pn)>1的个数。要满足上式,需要满足n*pn为偶数,其实就是求奇数个数的排列乘上偶数个数的排列。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 998244353;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;

void solve() {
    int n;
    scanf("%d", &n);
    if (n % 2 == 1) {
        printf("0\n");
        return;
    }
    ll ans = 1;
    for (int i = 1; i <= n / 2; i++) {
        ans = (ans * i) % mod;
    }
    ans = (ans * ans) % mod;
    printf("%d\n", ans);
}

int main(int argc, char** argv) {
    int _t;
    scanf("%d", &_t);
    while (_t--) {
        solve();
    }
    return 0;
}

C.Shinju and the Lost Permutation

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;

const int N = 1e5 + 10;
int c[N];

void solve() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
    }
    bool flag = true;
    int cnt = 0;
    c[n + 1] = c[1];
    for (int i = 1; i <= n; i++) {
        if (c[i + 1] > c[i] + 1) {
            flag = false;
        }
        if (c[i] == 1) {
            cnt++;
        }
    }
    if (flag && cnt == 1) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
}

int main(int argc, char** argv) {
    int _t;
    scanf("%d", &_t);
    while (_t--) {
        solve();
    }
    return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值