zoukankan      html  css  js  c++  java
  • Hihocoder #1509 : 异或排序

    #1509 : 异或排序

    http://hihocoder.com/problemset/problem/1509

    分析:

      如果a[i]和a[i+1]的相同的位,那么可以不用考虑了,找到它们第一个不同的位置,它限制了S的这个位置必须是多少。

      最后答案就是没有限制的位的随便选。如果一个位限制了两次,且数字不同,那么答案就是0。

      dls:别看n只有几十,但是它的复杂度是nlog(max{ai})!!!

    代码:

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<cctype>
     7 #include<set>
     8 #include<vector>
     9 #include<queue>
    10 #include<map>
    11 #define fi(s) freopen(s,"r",stdin);
    12 #define fo(s) freopen(s,"w",stdout);
    13 using namespace std;
    14 typedef long long LL;
    15 
    16 inline LL read() {
    17     LL x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    18     for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
    19 }
    20 
    21 const int N = 100;
    22 
    23 LL a[N], b[N];
    24 
    25 int main() {
    26     
    27     int n = read();
    28     for (int i=1; i<=n; ++i) a[i] = read();
    29     
    30     memset(b, -1, sizeof(b));
    31     
    32     for (int i=1; i<n; ++i) {
    33         for (int j=59; j>=0; --j) {
    34             int t1 = (a[i] >> j) & 1, t2 = (a[i + 1] >> j) & 1;
    35             if (!t1 && t2) { // 0 1
    36                 if (b[j] == -1 || b[j] == 0) { b[j] = 0; break; }
    37                 else { cout << 0; return 0; }
    38             }
    39             if (t1 && !t2) { // 1 0
    40                 if (b[j] == -1 || b[j] == 1) { b[j] = 1; break; }
    41                 else { cout << 0; return 0; }
    42             }
    43         }
    44     }
    45     
    46     LL cnt = 0;
    47     for (int j=59; j>=0; --j) 
    48         if (b[j] == -1) cnt ++;
    49     cout << (1ll << cnt);
    50     return 0;
    51 }
  • 相关阅读:
    BZOJ 4408: [Fjoi 2016]神秘数
    51Nod 1317 相似字符串对
    51Nod 1561 另一种括号序列
    BZOJ 4556: [Tjoi2016&Heoi2016]字符串
    51Nod 1048 整数分解为2的幂 V2
    BZOJ 4698: Sdoi2008 Sandy的卡片
    BZOJ 3571: [Hnoi2014]画框
    BZOJ 2752: [HAOI2012]高速公路(road)
    BZOJ 1095: [ZJOI2007]Hide 捉迷藏
    BZOJ 4537: [Hnoi2016]最小公倍数
  • 原文地址:https://www.cnblogs.com/mjtcn/p/9759289.html
Copyright © 2011-2022 走看看