【瞎搞】HDU 5014 Number Sequence 构造

题意:使得两个0-n的数列两两异或的和最大

异或 0^0=0

1^0=1

0^1=1

1^1=0

要求最大就意味着两个数尽可能多的互补 他0的位子你要1 


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <math.h>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define IN     freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 1000006;//点数的最大值
const int MAXM = 20006;//边数的最大值
const int INF = 1101521204;
const int mod = 10000007;
int a[120006],aa[120002];
int main()
{
    int n;
    //IN;
    while(scanf("%d",&n)!=EOF)
    {
        LL sum=0;
        cler(aa,-1);
        for(int i=0;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        for(int i=n;i>=0;i--)
        {
            int out;
            if(aa[i]==-1)
            {
                for(int j=0;j<=17;j++)
                    if((1<<j)-1>=i)
                    {
                        out=(1<<j)-1;
                        break;
                    }
                aa[i]=out-i;
                aa[out-i]=i;
            }
        }
        printf("%I64d\n",sum*2);
        for(int i=0;i<=n;i++)
            printf("%d%c",aa[a[i]],i==n?'\n':' ');
    }
}


posted @ 2014-09-14 19:43  kewowlo  阅读(116)  评论(0编辑  收藏  举报