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

位运算之a^b

时间:2019-01-20 00:52:44      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:www   运算   rgs   子集   math   ati   个数   color   tail   

题目链接:https://www.acwing.com/problem/content/91/

参考链接:https://blog.csdn.net/chaiwenjun000/article/details/71154235

       https://blog.csdn.net/qq_30076791/article/details/50571194

       https://blog.csdn.net/riba2534/article/details/79834558

  1. 二进制中子集的个数以及每个子集的具体内容

比如有5个小球,如果每个小球都被选中的话,这可以用二进制11111来表示。依此类推如果都没有被选中,则是00000。那么求出这5个小球被选中的所有可能状态,用二进制表示。

public class Main {
    public static void main(String[] args) {
        int x= (int) (Math.pow(2,5)-1);//表示5个小球都被选中的状态11111:十进制表示为2^5-1
        int n=0;
        for(int i=x;i!=0;){
            i=(i-1)&x;
            n++;
            System.out.println(Integer.toBinaryString(i));//每个子集的具体内容
        }
        System.out.println("n=="+n);//子集个数
    }
}

 

位运算之a^b

标签:www   运算   rgs   子集   math   ati   个数   color   tail   

原文地址:https://www.cnblogs.com/clarencezzh/p/10293748.html

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