zoukankan      html  css  js  c++  java
  • SPOJ XMAX

    XMAX - XOR Maximization

    Given a set of integers S = { a1, a2, a3, ... a|S| }, we define a function X on S as follows:
    X( S ) = a1 ^ a2 ^ a3 ^ ... ^ a|S|.
    (^ stands for bitwise 'XOR' or 'exclusive or')

    Given a set of N integers, compute the maximum of the X-function over all the subsets of the given starting set.

    Input

    The first line of input contains a single integer N, 1 <= N <= 105.
    Each of the next N lines contain an integer ai, 1 <= ai <= 1018.

    Output

    To the first line of output print the solution.

    Example

    Input:

    3
    1
    2
    4
    Output:

    7

    高斯消元类似。尽量变幻成上三角矩阵。每一位尽量留一个1

    如矩阵:

    010000

    001000

    000100

    000010

    就是一个理想的矩阵。

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/9/8 15:30:01
    File Name     :spoj_XMAX.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 100010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(ll a,ll b){
        return a>b;
    }
    ll a[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int n;
        while(cin>>n){
            for(int i=1;i<=n;i++)cin>>a[i];
            sort(a+1,a+1+n,cmp);
            int row=1;
            for(int i=60;i>=0;i--){
                for(int j=row;j<=n;j++){
                    if(a[j]&(1LL<<i)){
                        swap(a[row],a[j]);
                        for(int k=1;k<=n;k++){
                            if((a[k]&(1LL<<i))&&(k!=row)){
                                a[k]=a[k]^a[row];
                            }
                            //puts("YES");
                        }
                        row++;
                    }
                }
            }
            ll ans=0LL;
            for(int i=1;i<=n;i++){
            //    cout<<a[i]<<endl;
                ans^=a[i];
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Windows Phone App的dump 文件分析
    博客园客户端UAP开发随笔 -- App的心动杀手锏:动画
    博客园客户端UAP开发随笔--自定义控件的左膀右臂
    新年快乐
    博客园客户端(Universal App)开发随笔
    博客园 UAP 的部分反馈回复
    博客园客户端(Universal App)开发随笔 -- 样式管理与夜间模式
    Hadoop专业解决方案-第5章 开发可靠的MapReduce应用
    胖子哥的大数据之路(6)- NoSQL生态圈全景介绍
    NoSQL高级培训课程-HBase&&MongoDB(两天版)
  • 原文地址:https://www.cnblogs.com/pk28/p/5853609.html
Copyright © 2011-2022 走看看