zoukankan      html  css  js  c++  java
  • codeforce 165E Compatible Numbers

      题意 有集合 {ai} i = 1,2,3,...n 找出集合里面是否有与之相容的,x&y == 0  也就是,已知存在一个二进制数字 x (相当于有n个1组成),寻找一个 y (有 1 的地方跟 x 不一样)。

      当然,在R里有很多满足题意的 y (1放的位置不同,以及1的数量不同),所以从inf开始往前将 x 提供给所有可以扩展给 y (添加几个1的数)

    #include <stdio.h>
    #include <string.h>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    
    using namespace std;
    const int inf = (1<<22);
    const int maxm = 4e6+10;
    const int maxn = 1e7+10;
    int a[maxn];
    int b[inf];
    int n, m;
    int main () {
            scanf("%d",&m);
            for (int i = 1; i <= m; i++) {
                scanf("%d", &a[i]);
                b[inf-a[i]-1] = a[i];
            }
            for (int i = inf-1; i >= 0; i--) {
                if (!b[i]) {
                    for (int j = 0; j < 22; j++) {
                        if (b[i|(1<<j)]) {
                            b[i] = b[i|(1<<j)];
                        }
                    }
                }
            }
              for (int i = 1; i <= m; i++) {
                if (i-1) {
                    printf(" ");
                }
                if (b[a[i]]) {
                    printf("%d", b[a[i]]);
                } else {
                    printf("-1");
                }
            }puts("");
        return 0;
    }
    View Code
  • 相关阅读:
    Android 自定义ProgressDialog
    Android 设置TextView字体颜色
    Android 隐藏EditText的焦点
    Android TextView点击效果
    区间问题 codeforces 422c+hiho区间求差问
    hdu 5651 重复全排列+逆元
    hdu 1576
    C Looooops
    扩展欧几里得模板
    hdu 6025(女生赛)
  • 原文地址:https://www.cnblogs.com/Urchin-C/p/11233711.html
Copyright © 2011-2022 走看看