BNU 29364 Invading system【签到】

链接:



I. Invading system

1000ms
1000ms
65536KB
64-bit integer IO format:  %lld      Java class name:  Main
Font Size:   
    Eyelids is a student in WHU, at the same time he is a hacker. Shortly after the end of the examination, he was surprised to find he had failed in advanced mathematics, so he decisively invaded School Academic Department website. In the process of invasion, he found that the contents related to the score is an encrypted file, this file consisted by n numbers, after analysis, he find the password of the encrypted file was the number whose binary form has the least 1 among these n numbers. However, as there are too many numbers, Eyelids hopes you can help him decipher the password, to change the score before the results will be finally announced. 

Input

    The first line is an integer T indicates the number of test cases.

    Input contains multiple test cases. 

    For each test case, the first line has a number n (1<=n<=10^5), showing the number of the numbers. The second line contains n integers separated by blank, showing the n numbers in the file (1<=ai<=10^9).

Output

    For each set of data, output the case number first, then the key in a line. If there are more than one number are eligible, output the smallest one.

Sample Input

1
5
3 2 4 5 6

Sample Output

 
        
    
   
   
Case 1: 2


总结:第一场组队赛来迟了。Orc先是一个人战,最后 lrbj 又出了一题,就我表现最不好了。赛后又在死磕前面未完成的计算几何,先贴个签到的代码吧。
           后面的要快点做完。

code:

/**
题意:给你一系列的数字,把他们转换成二进制,求出二进制中的数字 1 的个数
       输出 1 的个数最少的,且数值最小的数字。
*/
#include<stdio.h>

int cal(int n)
{
    int ans = 0;
    while(n > 0)
    {
        if(n&1) ans++; //如果是奇数 +1 偶数 0 不管
        n >>= 1;
    }
    return ans;
}
int main()
{
    int T;
    int n;
    scanf("%d", &T);
    for(int t = 1; t <= T; t++)
    {
        scanf("%d", &n);
        int a;
        scanf("%d", &a);
        int ans = a; //先找第一个数
        int bin = cal(a);
        
        for(int i = 1; i < n; i++)
        {
            scanf("%d", &a);  
            if(cal(a) < bin ||(cal(a) == bin && a < ans) )
            {// 1 的个数更小, 或者 1 的个数一样,但是数值更小
                bin = cal(a); ans = a;
            }
        }
        printf("Case %d: %d\n", t,ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值