Codeforces Round #752 (Div. 2)(A~D)

题目链接

A. Era

题意

  1. 给我们一个长度为 n 的序列 ai,我可以向 ai 中插入一些数字,然后使 ai >= i。

思路

  1. 找到所有 ai - i 的最大值 mx 就可以了,我们在 a 数组前边插入 mx 个 1 就可以了。

代码

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

const int N = 1e5 + 10;
int n, m;
int a[N];



int main()
{
    
    
    int T; scanf("%d", &T);
    while (T --)
    {
    
    
        scanf("%d", &n);
        int ans = 0;
        for (int i = 1; i <= n; i ++) {
    
    
            scanf("%d", &a[i]);
            ans = max(ans, a[i] - i);
        }
        printf("%d\n", ans);
    }




    return 0;
}

B. XOR Specia-LIS-t

题意

  1. 给一个长为 n 数组 a [ ], 然后我们可以把这个数组分割成若干段,每一段的权值为:这个子段的最长上升子序列的个数,使这若干段的权值异或和为 0,如果存在一种方案的话则输出 yes,否则输出 no。

思路

  1. 当 n 为偶数的时候,每个元素单独形成一段就行了。
  2. 当 n 为奇数的时候,判断是否存在一个下标 i,使 a [i] <= a [i - 1] , 如果有的话,让 i 和 i-1 形成一组,其他的每个元素单独形成一组。
  3. 当 n 为奇数,但是不存在 a [i]<=a [i-1] 的情况,此时 a 是一个严格递增的数组,一定无解。

代码

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

const int N = 1e5 + 10;
int n, m;
int a[N];



int main()
{
    
    
    int T; scanf("%d", &T);
    while (T --)
    {
    
    
        scanf("%d", &n);
        int flag = n % 2 == 0;
        for (int i = 1; i <= n; i ++) {
    
    
            scanf("%d", &a[i]);
            if (i > 1 && a[i] <= a[i - 1])
            {
    
    
                flag = 1;
            }
        }

        if (flag) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

C. Di-visible Confusion

代码

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

const int N = 1e5 + 10;
int n, m;
int a[N];


int main()
{
    
    
    int T; scanf("%d", &T);
    while (T --)
    {
    
    
        int flag = 1;
        scanf("%d", &n);
        for (int i = 1; i <= n; i ++) {
    
    
            scanf("%d", &a[i]);

            if (a[i] % (i + 1) == 0)
            {
    
    
                int p = 2;
                while (a[i] % p == 0)
                    p ++;
                p --;
                if (i <= p)
                    flag = 0;
            }
        }

        if (flag)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}

D. Moderate Modular Mode

代码

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


int main()
{
    
    
    int T; scanf("%d", &T);
    while (T --)
    {
    
    
        int x, y;
        scanf("%d %d", &x, &y);
        int ans;

        if (y % x == 0)
        {
    
    
            ans = y;
        }
        else if (x > y)
        {
    
    
            ans = x + y;
        }
        else if (x == y)
        {
    
    
            ans = x;
        }
        else
        {
    
    
            ans = y - y % x / 2;
        }

        printf("%d\n", ans);
    }

    return 0;
}

Guess you like

Origin blog.csdn.net/qq_34261446/article/details/121068602