Educational Codeforces Round 139 A~D(补题)

A - Extremely Round

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll T, n;
ll m;
ll a[N];
ll sum;
void solve ()
{
    char b[N] = {0};
    cin >> b;
    ll x = strlen (b);
    ll num = 9 * (x - 1) + b[0] - '0';
    cout << num << endl;
}
int main()
{
    cin >> T;
    while (T--) {
		solve(); 
    }
    return 0;
}

B - Notepad#

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll T, n;
ll m;
ll a[N];
ll sum;
ll f;
string solve ()
{
    cin >> n;
    char b[N];
    cin >> b;
    if (n <= 3)
        return "No\n";
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 2; j < n - 1; j++) {
            if (b[i] == b[j] && b[i + 1] == b[j + 1])
                return "YES\n";
        }
    }
    return "NO\n";
}
int main()
{
    cin >> T;
    while (T--) {
		cout << solve(); 
    }
    return 0;
}

C - Hamiltonian Wall

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll T, n;
ll x, y;
ll a[N];
string s[2];
ll sum;
ll f, ok;
void solve () {
    cin >> n;
    cin >> s[0] >> s[1];
    for (int i = 0; i < 2; i++) {
        f = 1;
        x = i;
        for (int j = 0; j < n; j++) {
            if (s[x][j] != 'B')
                f = 0;
            if (s[!x][j] == 'B')
                x ^= 1; 
        }
        if (f) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}
int main() {
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

D - Lucky Chains

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll T, n;
ll x, y;
ll pri[N];
string s[2];
ll sum, res;
ll f, ok;
void solve () {
    cin >> x >> y;
    ll d = y - x;
    if (d == 1) {
        cout <<"-1\n";
        return;
    }
    res = llinf;
    while (d > 1) {
        int p = pri[d];
        d /= p;
        res = min (res, (p - x % p) % p);
    }
    cout << res << endl;
}
int main() {
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    for (int i = 2; i <= N; i++) {
        if (pri[i] == 0) {
            for (int j = i; j <= N; j += i) {
                pri[j] = i;
            }
        }
    }
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值