zoukankan      html  css  js  c++  java
  • [HDOJ3711]Binary Number(枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3711

    题意:两个数集合,找二进制下位数不同最少的数,如果一样,找集合数最小的。

    暴力枚举

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn = 110;
     5 int n, m;
     6 int a[maxn], b[maxn];
     7 
     8 int ok(int x, int y) {
     9   int xx = x, yy = y;
    10 
    11   int cnt = 0;
    12   if(x > y) swap(x, y);
    13   while(x) {
    14     if((x&1)!=(y&1)) cnt++;
    15     x >>= 1; y >>= 1;
    16   }
    17   while(y) {
    18     if(y&1) cnt++;
    19     y >>= 1;
    20   }
    21   return cnt;
    22 }
    23 
    24 int main() {
    25   //freopen("in", "r", stdin);
    26   int T;
    27   scanf("%d", &T);
    28   while(T--) {
    29     scanf("%d %d", &n, &m);
    30     for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    31     for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
    32     for(int i = 1; i <= m; i++) {
    33       int ret = 9000000, k;
    34       for(int j = 1; j <= n; j++) {
    35         int tmp = ok(b[i], a[j]);
    36         if(ret > tmp) {
    37           ret = tmp;
    38           k = j;
    39         }
    40         else if(ret == tmp) {
    41           if(a[k] > a[j]) k = j;
    42         }
    43       }
    44       cout << a[k] << endl;
    45     }
    46   }
    47   return 0;
    48 }
  • 相关阅读:
    P4281 [AHOI2008]紧急集合 / 聚会
    P2622 关灯问题II
    CF1092F Tree with Maximum Cost
    10.28记
    威尔逊定理及证明
    CF895C Square Subsets
    洛谷 P5556 圣剑护符
    Multi-nim结论及证明
    AT2667 [AGC017D] Game on Tree
    洛谷 P4643 [国家集训队]阿狸和桃子的游戏
  • 原文地址:https://www.cnblogs.com/kirai/p/5957973.html
Copyright © 2011-2022 走看看