Codeforces Round #631 (Div. 2)

A

用桶维护即可

#include <bits/stdc++.h>
using namespace std;

const int N = 205;

int t,n,x,a[N],b[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>n>>x;
        for(int i=1;i<=n;i++) cin>>a[i];
        memset(b,0,sizeof b);
        for(int i=1;i<=n;i++) b[a[i]]=1;
        int pos=1;
        while(x) {
            while(b[pos]) ++pos;
            b[pos]=1;
            --x;
        }
        pos=1;
        while(b[pos]) ++pos;
        cout<<pos-1<<endl;
    }
}

B

显然分出的两段是合法的,当且仅当

  • 段的最大值等于段的长度
  • 段内没有重复元素

于是先扫一遍得到正序倒序第一个重复元素的位置,再正反各扫一遍得到前缀后缀最大值即可

#include <bits/stdc++.h>
using namespace std;

const int N = 205;

int t,n,x,a[N],b[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>n>>x;
        for(int i=1;i<=n;i++) cin>>a[i];
        memset(b,0,sizeof b);
        for(int i=1;i<=n;i++) b[a[i]]=1;
        int pos=1;
        while(x) {
            while(b[pos]) ++pos;
            b[pos]=1;
            --x;
        }
        pos=1;
        while(b[pos]) ++pos;
        cout<<pos-1<<endl;
    }
}

C

不合法当且仅当总长度不够,或者存在 \(i\) 使得 l[i]+i-1>n

如果合法,我们先令 \(p_i = i\),然后 \(i\) 从大到小遍历将它放到最右端即可

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100005;

int n,m,l[N],p[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>n>>m;
    int sum=0;
    for(int i=1;i<=m;i++) cin>>l[i], sum+=l[i];
    for(int i=1;i<=m;i++) if(l[i]+i-1>n) {
        cout<<-1; return 0;
    }
    if(sum<n) {
        cout<<-1; return 0;
    }
    for(int i=1;i<=m;i++) p[i]=i;
    int len=n;
    for(int i=m;i>=1;--i) {
        if(len-l[i]>i-1) p[i]=len-l[i]+1,len-=l[i];
        else break;
    }
    for(int i=1;i<=m;i++) cout<<p[i]<<" ";
}

D

待补

原文地址:https://www.cnblogs.com/mollnn/p/12630252.html

时间: 2024-08-03 10:57:13

Codeforces Round #631 (Div. 2)的相关文章

Codeforces Round #631 (Div. 2) D.Dreamoon Likes Sequences

题目连接:Dreamoon Likes Sequences  题意:给你d和m,让你构造一个递增数组a,使数组b(i==1,b[i]=a[i] ; i>1, b[i]=b[i-1]^a[i])递增,求a有几种,答案模m. 题解:根据异或的性质可以得出:2后边不能有3, 4后边不能有5~7, 8后边不能有9~15...... 然后就很好写了.用数组b记录第i个数可以取得数有多少个,数组dp记录长度为 i 的 a 数组有几种.看下边的代码应该就清楚了. 1 #include<bits/stdc++

Codeforces Round #631 (Div. 2) - Thanks, Denis aramis Shitov!

A题 题意: 给n个数据,m次操作,使得1~A,全都出现.如果其中有数据没在n里出现,就m-- 思路: 模拟就行 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define ull unsigned long long 5 #define il inline 6 #define it register int 7 #define inf 0x3f3f3f3f 8 #define lowbit

Codeforces Round #631 (Div. 2) Dreamoon Likes Sequences

题面很短,别的博客也讲了就不说题意了. 做法: 异或是没有进位的加法,所以ai + 1的二进制最高位要大于ai的二进制最高位,才能满足ai递增,bi也递增的条件.呐这样的话,选了4,(5,6,7)就都不能选了,只能选比7大的数. 这样分析下来a数组最长也只有30,(2^30>1e9) 直接按照数字大小dp会TLE 思路角度1:换一个角度,我们把二进制最高位相同的看作一组,因为这一组内只能选一个数. 有点像分组背包.但是我们现在只看分组背包的方案数,所以就不用枚举每一组内的物品了. dpij表示考

Codeforces Round #631 (Div. 2) B. Dreamoon Likes Permutations(排列组合)

The sequence of mm integers is called the permutation if it contains all integers from 11 to mm exactly once. The number mm is called the length of the permutation. Dreamoon has two permutations p1p1 and p2p2 of non-zero lengths l1l1 and l2l2 . Now D

Codeforces Round #631 (Div. 2) C. Dreamoon Likes Coloring(贪心好题/意识流题解)

Dreamoon likes coloring cells very much. There is a row of nn cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 11 to nn . You are given an integer mm and mm integers l1,l2,…,lml1,l2,…,lm (1≤li≤n1≤li≤n ) Dreamoo

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd