Educational Codeforces Round 74 (Rated for Div. 2)

A
除了1以外每个数都可以被质数构成

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
    int t; cin >> t;
    while (t--) {
        ll x, y; cin >> x >> y;
        if (x == y || x == y + 1) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

B
排序去重,暴力

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int a[maxn];
 
int main()
{
    int q; cin >> q;
    while (q--) {
        int n, r; cin >> n >> r;
        for (int i = 1; i <= n; ++i)
            cin >> a[i];
        sort(a + 1, a + n + 1);
        n = unique(a + 1, a + n + 1) - a - 1;
        int sum = 0, cnt = 0;
        for (int i = n; i >= 1; --i) {
            if (a[i] <= sum) break;
            cnt++; sum += r;
        }
        cout << cnt << endl;
    }
}

C
贪心,判断下一块板和下下一块板的距离差,大于2则将下一块板下面的板露出来

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
、int h[maxn];
int main()
{
    int q; cin >> q;
    while (q--) {
        int H, n; cin >> H >> n;
        for (int i = 1; i <= n; ++i)
            cin >> h[i];
        h[++n] = 0;
        int ans = 0;
        for (int i = 1; i < n; ++i) {
            if (i == n - 1) continue;
            if (h[i + 1] == h[i + 2] + 1) i++;
            else {
                h[i + 1]--;
                ans++;
            }
        }
        cout << ans << endl;
    }
}

D
正难则反,思考存在字符不属于任意回文串的字串数量。
一个字串,有一种字母只出现一次而且出现在字串头尾,该字串就不合法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 5;
char str[maxn];
ll a[maxn];
int main()
{
    int n;
    scanf("%d%s", &n, &str);
    int cnt = 0, tot = 0;
    for (int i = 0; i < n; ++i) {
        cnt++;
        if (str[i] != str[i + 1]) {
            a[tot++] = cnt;
            cnt = 0;
        }
    }
    ll ans = (ll)n * (n - 1) / 2;
    for (int i = 1; i < tot; ++i)
        ans -= (a[i] + a[i - 1] - 1);
    printf("%lld\n", ans);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值