BNU Invading system
http://www.bnuoj.com/bnuoj/problem_show.php?pid=29364
 
  这个题被坑了。
 
  题意:密码就是那些数字里面的数,转换成二进制后1最少的那个数,当1的个数相同的时候,要选最小的那个数。
 
  AC代码:
 
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
    return a < b;
}
int main()
{
    int t,n,i,k,mi,x,p,q;
    int a[100010];
    scanf("%d",&t);
    k = 0;
    p = 2;
    while(t--)
    {
        k++;
        scanf("%d",&n);
        q = 100000;
        for(i = 0; i < n; i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);  //一开始没有排序,一直WA。。英语硬伤。。
        for(i = 0; i < n; i++)
        {
            x = 0;
            p = a[i];
            while(p!=0)
            {
                if(p&1)
                {
                    x++;
                }
                p = p>>1;
            }
            if(x < q)
            {
                q = x;
                mi = a[i];
            }
        }
        printf("Case %d: %d\n",k,mi);
    }
    return 0;
}
 
                    
                 
                
            
         
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号