Codeforces Round #735 (Div. 2)

codeforces round 735(div.2)

A. Cherry

  • 题意

给你一个序列\(a_i\), 让你找到一对l, r 另max(\(a_l \to a_r\) ) * min(\(a_l \to a_r\)) 最大

  • 思路

多思考一下,发现直接算相邻就可以了,多的也没意义

code:

const int N = 300100;
const double pi = 3.1415927536;
const double INF = 1e9;
const double eps = 1e-6;

int a[N];

void solve(){
    int n;
    cin >> n;
    for(int i = 1;i <= n;i ++) {
        cin >> a[i];
    }
    int maxn = a[1], minn = a[1];
    int ans = 0;
    for(int i = 2;i <= n;i ++) {
        ans = max(ans, a[i] * a[i - 1]);
    }
    cout << ans << endl;
}

B. Cobb

  • 题意

给一个序列\(a_i\) 和一个k, 找到最大的 \(i \cdot k - k \cdot (a_i | a_j)\)\(1 <= i < j <= n\) \(k \in (min(100, n))\)

  • 思路

直接暴力是肯定不行的,那么我们看到k只有100, 那大的时候,不管后面多大,肯定没有前面大,那就去枚举最后面的一部分就行了

code:

const int N = 200100;
const int INF = 1e9;
int a[N];

void solve(){
    int n,k;
    cin >> n >> k;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    if(n <= 200) {
        ll ans = -INF;
        for(int i = 1;i < n;i ++) {
            for(int j = i + 1;j <= n;j ++) {
                ans = max(ans, 1LL * i * j - k * (a[i] | a[j]));
            }
        }
        cout << ans << endl;
    }else {
        ll ans = -INF;
        for(int i = n - 100;i < n;i ++) {
            for(int j = i + 1;j <= n;j ++) {
                ans = max(ans, 1LL * i * j - k * (a[i] | a[j]));
            }
        }
        cout << ans << endl;
    }
    
}

C. Mikasa

  • 题意

给出n和m, 求一个\(\operatorname{MEX} (n \oplus 1 ··· n \oplus m)\).

  • 思路

打表,二进制规律,取出n ^ m的前k位 ^ 1 = s, 若 s ^ n > m, 那么s必没有出现过

code:

void solve(){
    int n, m;
    cin >> n >> m;

    if(n > m) {
        cout << "0" << endl;
        return;
    }
    int now = 0;
    int ans = m + 1;
    for(int i = 31;i >= 0;i --) {
        now = (n ^ m) >> i << i;
        now ^= 1 << i;
        if((now ^ n) > m) {
            ans = min(now,ans);
        }
    }
    cout << ans << endl;
}

D. Diane

  • 题意

构造一个字符串s,另它的任何子字符串出现的次数为奇数,子字符串就是通过删除s的部分头部和部分尾部形成的子串

  • 思路

构造一下昂,我想的是aaacbbbaaaabbbb这样,改变前面奇数a,b,后面偶数a,b中间加个cde就行了

code:

void solve(){
    int n;
    cin >> n;
    if(n <= 26) {
        string ans = "";
        for(int i = 0;i < n;i ++) {
            ans += ('a' + i);
        }
        cout << ans << endl;
        return;
    }
    int k = (n - 1) / 2;
    string ans = "";
    int t = n - k * 2;
    if(k % 2 == 0) t += 2, k -= 1;
    for(int i = 1;i <= k / 2;i ++) {
        ans += 'a';
    }
    for(int i = 1;i <= t;i ++) {
        ans += ('b' + i);
    }
    for(int i = 1;i <= k / 2;i ++) {
        ans += 'b';
    }
    for(int i = 1;i <= k / 2 + 1;i ++) {
        ans += 'a';
    }
    for(int i = 1;i <= k / 2 + 1;i ++) {
        ans += 'b';
    }
    cout << ans << endl;
}
posted @ 2021-07-30 09:38  darker_wxl  阅读(52)  评论(0编辑  收藏  举报
window.onload = function(){ $("#live2dcanvas").attr("style","position: fixed; opacity: 0.7; left: 70px; bottom: 0px; z-index: 1; pointer-events: none;") }