Live2D
博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

6.12考试 T2 子集

n=4s={4,3,2,1}15

n=4{4,3,2,1}154

{1}0001{2}0010{1,2}0011{3}0100...{1,2,3,4}1111

1,2,3...,15

{1,2,4}101111{1,2,4}11

nm{1,2...,n}m

 一行n,m

   m

输出样例1:

4 11

输出样例1:

1 2 4

该题其他输入输出数据:https://share.weiyun.com/56A6FlF

思路:

  对m进行二进制分解。

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

int n,m;

int main()
{
    freopen("subset.in","r",stdin);
    freopen("subset.out","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        if(m&1) printf("%d ",i);
        m>>=1;
    }
    //cout<<n<<" "<<m;
    return 0;
}

 

posted @ 2019-06-12 15:06  _hhs  阅读(205)  评论(0编辑  收藏  举报