Educational Codeforces Round 63 (Rated for Div. 2) A,B,C

A. Reverse a Substring

传送门

就是找不满足升序排列的字母,输出就行了。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3e5 + 10;
char s[maxn];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
#endif // ONLINE_JUDGE
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin >> t;
    cin >> s;
    int flag = 0,l,r;
    for(int i = 1;i < t; i++)
    {
        if(s[i - 1] > s[i])
        {
            flag = 1;
            l = i;
            r = i + 1;
            break;
        }
    }
    if(flag)
    {
        cout << "YES" << endl << l << " " << r << endl;
    } else
        cout << "NO" << endl;
    return 0;
}

B. Game with Telephone Numbers

传送门

在前n - 11 + 1个数字里找8,如果8的个数超过一半,就OK;

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
char s[maxn];
int main()
{
    int t;
    scanf("%d\n%s",&t,s);
    int ans = 0;
    int x = (t - 11) / 2;
    for(int i = 0;i <= 2 * x; i++){
        if(s[i] == '8')
            ans++;
    }
    if(ans > x )
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

C. Alarm Clocks Everywhere

传送门

X数组的差值两两GCD,然后判断这个值是否在P数组里出现过就行了,但是这个值可以是P的倍数,所以判断是否对P取模为零即可。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3e5 + 10;
ll x[maxn],p[maxn],a[maxn],ans[maxn];
ll gcd(ll a,ll b)
{
    return b ? gcd(b,a % b) : a;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
#endif // ONLINE_JUDGE
    cin.tie(0);
    cout.tie(0);
    ll n,m,k = 0;
    cin >> n >> m;
    for(int i = 0;i < n; i++)
    {
        cin >> a[i];
        if(i)
            x[i - 1] = a[i] - a[i - 1];
    }
    ll ans;
    for(int i = 0;i < n - 1; i++)
    {
        if(i == 0)
            ans = x[i];
        else
        {
            ans = gcd(ans,x[i]);
        }
    }
    int flag = 0;
    for(int i = 1;i <= m; i++)
    {
        cin >> p[i];
        if(ans % p[i] == 0)
        {
            flag = i;
        }
    }
    if(flag)
        cout << "YES" << endl << a[0] << " " << flag << endl;
    else
        cout << "NO" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xiao__hei__hei/article/details/89477359