Codeforces Global Round 2 Solution

这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 E-> Div.1 F->Div.1 F简直有毒

只AC 4题似乎就是1000+名了

这种考验手速的时刻Itst就比较擅长了,然后就红名+拿衣服了……

A. Ilya and a Colorful Walk

如果最左边和最右边不同就是\(N-1\),否则就是中间跟两边颜色不同的块到两边距离的最大值

#include<bits/stdc++.h>
//This code is written by Itst
using namespace std;

inline int read(){
    int a = 0;
    char c = getchar();
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)){
        a = a * 10 + c - 48;
        c = getchar();
    }
    return a;
}

const int MAXN = 3e5 + 7;
int col[MAXN] , N;

signed main(){
    N = read();
    for(int i = 1 ; i <= N ; ++i)
        col[i] = read();
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i){
        if(col[i] != col[1]) ans = max(ans , i - 1);
        if(col[i] != col[N]) ans = max(ans , N - i);
    }
    cout << ans;
    return 0;
}

B. Alyona and a Narrow Fridge

二分答案,对于一个二分值\(mid\)将所有要放的牛奶拿出来,每一次最高的和次高的放在一层

#include<bits/stdc++.h>
//This code is written by Itst
using namespace std;

inline int read(){
    int a = 0;
    char c = getchar();
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)){
        a = a * 10 + c - 48;
        c = getchar();
    }
    return a;
}

#define int long long
const int MAXN = 3e5 + 7;
int hei[MAXN] , tmp[MAXN] , N , H;

signed main(){
    N = read(); H = read();
    for(int i = 1 ; i <= N ; ++i)
        hei[i] = read();
    int L = 0 , R = N;
    while(L < R){
        int mid = ((L + R + 1) >> 1);
        memcpy(tmp , hei , sizeof(int) * (N + 1));
        sort(tmp + 1 , tmp + mid + 1);
        int cur = 0 , sum = 0;
        for(int i = mid ; i ; --i)
            if(cur){
                sum += cur;
                cur = 0;
            }
            else cur = tmp[i];
        sum + cur <= H ? L = mid : R = mid - 1;
    }
    cout << R;
    return 0;
}

C. Ramesses and Corner Inversion

注意到对任意\(x \times y\)的矩形做操作,等价于对这个矩形内所有\(2 \times 2\)的子矩形做操作,于是我们只需要对\(2 \times 2\)的矩形做操作就可以了,这个直接从左往右、从上往下、要翻转就翻转就可以了

#include<bits/stdc++.h>
//This code is written by Itst
using namespace std;

inline int read(){
    int a = 0;
    char c = getchar();
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)){
        a = a * 10 + c - 48;
        c = getchar();
    }
    return a;
}

#define int long long
int arr[507][507] , to[507][507] , N , M;

signed main(){
    N = read(); M = read();
    for(int i = 1 ; i <= N ; ++i)
        for(int j = 1 ; j <= M ; ++j)
            arr[i][j] = read();
    for(int i = 1 ; i <= N ; ++i)
        for(int j = 1 ; j <= M ; ++j)
            to[i][j] = read();
    for(int i = 1 ; i < N ; ++i)
        for(int j = 1 ; j < M ; ++j)
            if(arr[i][j] != to[i][j]){
                arr[i][j] ^= 1;
                arr[i + 1][j] ^= 1;
                arr[i][j + 1] ^= 1;
                arr[i + 1][j + 1] ^= 1;
            }
    for(int i = 1 ; i <= N ; ++i)
        for(int j = 1 ; j <= M ; ++j)
            if(arr[i][j] != to[i][j]){
                puts("No");
                return 0;
            }
    puts("Yes");
    return 0;
}

D. Frets On Fire

题目相当于要求:有\(n\)条线段,左端点为\(s_i\)\(q\)组询问,每一组询问每条线段的长度都为\(l\),问线段覆盖总长度

\(s_{i+1} = INF\),那么答案就是\(\sum\limits_{i=1}^n \min\{s_{i+1} - s_i , l\}\)。把所有\(s_{i+1}-s_i\)存下来排个序,每一次询问时二分

#include<bits/stdc++.h>
//This code is written by Itst
using namespace std;

#define int long long
inline int read(){
    int a = 0;
    char c = getchar();
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)){
        a = a * 10 + c - 48;
        c = getchar();
    }
    return a;
}

const int MAXN = 1e5 + 7;
int N , Q , arr[MAXN] , delta[MAXN] , sum[MAXN];

signed main(){
    N = read();
    for(int i = 1 ; i <= N ; ++i)
        arr[i] = read();
    sort(arr + 1 , arr + N + 1);
    for(int i = 1 ; i < N ; ++i)
        delta[i] = arr[i + 1] - arr[i];
    sort(delta + 1 , delta + N);
    for(int i = 1 ; i < N ; ++i)
        sum[i] = sum[i - 1] + delta[i];
    Q = read();
    while(Q--){
        int l = read() , r = read() , del = r - l + 1;
        int t = upper_bound(delta + 1 , delta + N , del) - delta - 1;
        printf("%lld " , sum[t] + (N - t) * del);
    }
    return 0;
}

E. Pavel and Triangles

显然每一次选出的三角形的边长一定是\((2^i,2^i,2^j)\),其中\(j \leq i\)。所以可以从小往大贪心,每一次选择尽可能多的三角形,即先把\(< i\)的剩下的木棒尽可能地用掉,然后再3个3个地取当前剩余的木棒

#include<bits/stdc++.h>
//This code is written by Itst
using namespace std;

#define int long long
inline int read(){
    int a = 0;
    char c = getchar();
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)){
        a = a * 10 + c - 48;
        c = getchar();
    }
    return a;
}

const int MAXN = 1e5 + 7;
int N , num , ans;

signed main(){
    N = read();
    for(int i = 1 ; i <= N ; ++i){
        int val = read();
        if(val / 2 >= num){
            ans += num;
            val -= 2 * num;
            ans += val / 3;
            num = val % 3;
        }
        else{
            ans += val / 2;
            num -= val / 2;
            num += val % 2;
        }
    }
    cout << ans;
    return 0;
}

F. Niyaz and Small Degrees

留坑

G. Get Ready for the Battle

留坑

扫描二维码关注公众号,回复: 5799912 查看本文章

H. Triple

留坑

猜你喜欢

转载自www.cnblogs.com/Itst/p/10663274.html