HDOJ 3711 Binary Number

 1 #include <iostream>
 2 #include <algorithm>
 3 
 4 using namespace std;
 5 
 6 int cmp(const void *a,const void *b)
 7 {
 8     return *(int*)a-*(int*)b;
 9 }
10 
11 int cn(int x)
12 {
13    int c=0;
14    for(;x;x=x>>1)
15    {
16        if(x&1)
17         c++;
18    }
19    return c;
20 }
21 
22 int a[110];
23 int b[110];
24 
25 int main()
26 {
27 
28 int k;
29 cin>>k;
30 for(int ls=0;ls<k;ls++)
31 {
32     int n,m;
33     cin>>n>>m;
34 
35     for(int i=0;i<n;i++)
36         cin>>a[i];
37     for(int j=0;j<m;j++)
38         cin>>b[j];
39 
40     qsort(a,n,sizeof(int),cmp);
41 
42     int tot;
43     for(int i=0;i<m;i++)
44     {
45         int mini=99999999;
46         for(int j=0;j<n;j++)
47         {
48             int c;
49             c=b[i]^a[j];
50             if(mini>cn(c))
51             {
52                mini=cn(c);
53                tot=a[j];
54             }
55         }
56 
57         cout<<tot<<endl;
58     }
59 }
60 
61     return 0;
62 }

 

转载于:https://www.cnblogs.com/CKboss/archive/2013/04/11/3014166.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值