Codeforces Round #642 (Div. 3)A~D

Posted luoyugongxi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #642 (Div. 3)A~D相关的知识,希望对你有一定的参考价值。

A - Most Unstable Array

水题,特判1和2,1的时候输出0,2的时候输出原数,大于2的输出2*原数

B - Two Arrays And Swaps

水题*2,排序A,B数组,然后k次交换B数组最大和A数组最小,如果B数组最大小于等于A数组最小,就停止操作,求A数组之和

C - Board Moves

水题*3,规律题,把奇数的正方形分成四块,每块是这样递推的
… … …
:3 3 3
:3 2 2
:3 2 1
:3 2 1

所以递推公式

    ll c=2;
    a[3]=2;
    for(it i=5;i<maxn;i+=2){
        a[i]=a[i-2]+2*c*c;c++;
    }

D - Constructing the Array

题意:

构造一个数列,原本全是0的数列,找到数列最长的0子序列的l,r,找到中位数(l+r)/2的位置变成1~n,求出唯一的数列
样例解释:
Consider the array a of length 5 (initially a=[0,0,0,0,0]). Then it changes as follows:

Firstly, we choose the segment [1;5] and assign a[3]:=1, so a becomes [0,0,1,0,0];
then we choose the segment [1;2] and assign a[1]:=2, so a becomes [2,0,1,0,0];
then we choose the segment [4;5] and assign a[4]:=3, so a becomes [2,0,1,3,0];
then we choose the segment [2;2] and assign a[2]:=4, so a becomes [2,4,1,3,0];
and at last we choose the segment [5;5] and assign a[5]:=5, so a becomes [2,4,1,3,5].

思路:
用优先队列存,l,r,chang,l表示左边界,r表示右边界,chang表示0序列的长度,用优先队列找每次的最长长度。水题*4

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define il inline
#define it register int
#define inf 0x3f3f3f3f
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define mak(n,m) make_pair(n,m)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
const int maxn=2e5+10;
const int mo=1e9;
ll ksm(ll a,ll b){if(b<0)return 0;ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
int t;
int n,m;
int a[maxn];
struct node{
    int l,r,chang;
    friend bool operator<(const node a,const node b){
        if(a.chang==b.chang){
            return a.l>b.l;
        }
        return a.chang<b.chang;
    }
    node(){}
    node(int l1,int r1,int cc):l(l1),r(r1),chang(cc){}
};
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        mem(a,0);
        priority_queue<node>q;
        q.push(node(1,n,n));int z=1;
        while(!q.empty()){
            node kk=q.top();q.pop();
            int pos=(kk.l+kk.r)/2;
            a[pos]=z++;//cout<<pos<<" "<<kk.l<<" "<<kk.r<<" "<<kk.chang<<endl;
            if(kk.l==kk.r){continue;}
            else if(kk.l==pos){q.push(node(pos+1,kk.r,kk.r-pos));}
            else{
                q.push(node(pos+1,kk.r,kk.r-pos));
                q.push(node(kk.l,pos-1,pos-kk.l));
            }
        }
        for(it i=1;i<=n;i++){
            printf(i==n?"%d
":"%d ",a[i]);
        }
    }
    return 0;
}

E - K-periodic Garland

wa爆,找了一个样例
12 1
111111000011

答案应该是2

待会看题解,留个坑待补















以上是关于Codeforces Round #642 (Div. 3)A~D的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #642 (Div. 3)

Codeforces Round #642 (Div. 3)

Codeforces Round #642 (Div. 3)

Codeforces Round #642 (Div. 3) 题解

Codeforces Round #642 (Div. 3)A~D

Codeforces Round #642 (Div. 3)A~D