设为首页 加入收藏

TOP

zoj 3870 异或运算
2015-11-21 01:00:34 来源: 作者: 【 】 浏览:1
Tags:zoj 3870 运算

给你n个数 问有多少种情况 两两异或大于两个数中的最大值;

分析 如果a小于b 及大的为b 要想a^b大于b 及a的最高位(一定为1)与b的对应位不一样 及b的对应位为0 就一定满足 这样就转换为小的数的对应位

先排序 mark【i】表示i这个位置为0的数的个数

?

#include
  
   
#include
   
     #include
    
      #include
     
       using namespace std; int num[100010]; int cmp(int a,int b) { return a>b; } int main() { int T,i,j,n; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&num[i]); } sort(num+1,num+1+n,cmp); int record[100],mark[100]; memset(record,0,sizeof(record)); int ans=0; for(i=1;i<=n;i++) { j=1; int x=num[i]; while(x) { mark[j++]=x%2; x/=2; } ans+=record[j-1]; for(int k=1;k
      
       

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[LeetCode] Linked List Cycle 下一篇LeetCode 7: Reverse Integer

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: