码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-05-15 11:34:25      阅读:47      评论:0      收藏:0      [点我收藏+]

标签:序列   ssi   scan   cti   fir   bool   优先   c++   const   

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\n":"%d ",a[i]);
        }
    }
    return 0;
}

E - K-periodic Garland

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

答案应该是2

待会看题解,留个坑待补

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

标签:序列   ssi   scan   cti   fir   bool   优先   c++   const   

原文地址:https://www.cnblogs.com/luoyugongxi/p/12893699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!