zoukankan      html  css  js  c++  java
  • ZOJ

    传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3870

    题意:找出一个数列中的两个数,所有通过异或和使得结果同时大于这两个数;

    思路:先找出每个数在二进制下最高位 1 所在的下标;

       对于每个数,

         1/ 判断这个数的最后一位是不是 0,如果是 0,说明可以 和 最高位是这个位子(1)的数进行异或得到更大的数;

           结果加上有多少个这样的数;

          2/   对这个数进行( >>1 ), 右移一位的操作;

      ac代码

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    const int maxn = 100009;
    int a[maxn],sum[100];
    int get(int n)
    {
        int s=n,re=0;
        while(s)
        {
            s>>=1;
            re++;
        }
        return re;
    }
    int main(){
        //freopen("in","r",stdin);
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n;
            scanf("%d",&n);
            memset(sum,0,sizeof(sum));
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                sum[get(a[i])]++;
            }
            long long ans=0;
            for(int i=1;i<=n;i++)
            {
                int wei=1;
                while(a[i])
                {
                    if((a[i] & 1 )== 0)
                    {
                        ans+=sum[wei];
                    }
                    a[i]>>=1;
                    wei++;
                }
            }
            printf("%lld
    ",ans);
        }
    
        return 0;
    }
  • 相关阅读:
    企业生产环境不同业务linux系统分区方案
    linux 文件 s 权限
    shell中的命令与特殊符号
    Linux数组基础
    shell脚本学习(1)
    文件的压缩与打包
    Linux 磁盘管理基础命令df,du,fdisk,mke2fs
    mkpasswd的使用
    P1080 国王游戏
    P1315 观光公交
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/8633112.html
Copyright © 2011-2022 走看看