Codeforces Round #752 (Div. 2)


A. Era

思路:

对于任何一个a[i] > i来说,我们可以最多插入a[i] - i个1在最前面,所以最大值我们只需要把所有的a[i] - i取最大值就可以了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double PI = acos(-1);

int a[N], b[N];

int main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T -- )
    {
        int n;
        cin >> n;
        int res = 0;
        for (int i = 1; i <= n; i ++ )
        {
            int x;
            cin >> x;
            res = max(res, x - i);
        }
        cout << res << endl;
    }
    return 0;
}

B. XOR Specia-LIS-t

思路:

如果是偶数的话,我们可以分成偶数个只有一个数字的集合,这样偶数个1异或起来一定0。那么如果是奇数的时候我们就想办法把它凑成偶数个1,我们可以把两个不递增的数作为一个集合,这样这两个数作为一个1,就又有了偶数个1,所以奇数的时候我们只要看是否有这样的a[i] <= a[i-1]就行了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double PI = acos(-1);

int a[N], b[N];

int main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T -- )
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i ++ )
            cin >> a[i];
        
        if(n % 2 == 0) 
        {
            cout << "YES" << endl;
            continue;
        }

        bool flag = false;
        for (int i = 2; i <= n; i ++ )
            if(a[i] <= a[i - 1]) 
            {
                flag = true;
                break;
            }

        if(flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
        
    return 0;
}

C. Di-visible Confusion

思路:

对于第i个数,假如他前面的数能以某种方式被全部删除,那么我们看怎么删除第i个数,第i个数如果可以被删除,那么我们可以看从2到i+1这些数有没有不能被a[i]整除的,如果有这样的一个数k,那么我们在

a[i]是第k-1个数的时候删除a[i](因为删除的条件是a[i]不能整除i+1),所以根据数学归纳法前i个数都可以被删除,因此所有的数都要满足这个条件,所以当有一个数不满足这个条件时,即对于2到i+1的数都能整除,那就是NO

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double PI = acos(-1);

int a[N], b[N];

int main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T -- )
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i ++ )
            cin >> a[i];

        bool success = true;
        for (int i = 1; i <= n; i ++ )
        {
            bool flag = false;
            for (int j = 2; j <= i + 1; j ++ )
                if(a[i] % j != 0) 
                {
                    flag = true;
                    break;
                }

            if (!flag)
            {
                success = false;
                break;
            }
        }

        if(success)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
        
    return 0;
}

D. Moderate Modular Mode

思路;

显然对于x > y的情况很容易判断就是x + y,那么对于x <= y的情况我们可以这么考虑:

首先假设n < x:那么我们假设现在n%x = y%n是满足的,那我们分析一下,n%x此时等于n,而y%n此时小于n,所以矛盾

然后假设n > y:那么同样我们假设现在n%x = y%n是满足的,那我们分析一下,n%x此时小于x,而y%n此时等于y要大于等于x,所以矛盾

因此n在x和y之间。

然后我们可以通过画图来模拟分析这个过程:设我们此时在原点,然后每次步长为x向前走,直到不超过y,就像这样:

 

然后最大可到达的点p为y - y%x,我们此时要让n%x = y%n,所以n我们可以取p和y的中点,即可满足条件

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double PI = acos(-1);

int a[N], b[N];

int main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T -- )
    {
        int x, y;
        cin >> x >> y;
        if(x <= y)
            cout << y - y % x / 2 << endl;
        else
            cout << x + y << endl;
    }
        
    return 0;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM