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