zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    JSON1
    program的发展史及两个方法
    统计字符出现的次数
    美国十大web2.0公司背后的故事
    web history-----JavaScript 的起源故事
    Baidu_Map
    My json(Demo)
    program发展史及 forecast
    js事件类型
    字符统计与正则表达式
  • 原文地址:https://www.cnblogs.com/-hhs/p/11009754.html
Copyright © 2011-2022 走看看