njupt Keroro侵略地球

來源:互聯網
上載者:User

E. Keroro侵略地球

Keroro來侵略地球之前,曾跟Giroro伍長打賭:“我一個人滅掉整個地球給你看!”.
於是Keroro同學真的自己一個人來到地球開始他的侵略行動了。從K隆星出發之前,Keroro從Kururu曹長那兒拿了若干台左手武器{Li}和若干台右手武器{Ri},Keroro需要從{Li}裡選一台左手武器,從{Ri}裡選一台右手武器,用來組合成可用的恐怖武器。
左右手武器組合的規則很簡單,假設從{Li}選出來攻擊力為p的武器,從{Ri}選出來攻擊力為q的武器,組合起來的攻擊力就是p XOR q.

Keroro想知道,他能組合成的最強武器攻擊力為多少?

Hint:必須左右手武器都選出來一個,才能組合成可用武器

      XOR表二進位裡的“異或”操作,pascal語言裡是"xor", C/C++/Java裡是"^".

Input :
    第一行兩個整數n, m (1 <= n,m <= 100000), 表有n件左手武器,m件右手武器。
    第二行n個正整數{L},li表第i件左手武器的攻擊力,0 <= li <= 10^12
    第三行m個正整數{R},ri表第i件右手武器的攻擊力,0 <= ri <= 10^12
Output :

    最強組合武器的最大值。

思路:參看CF round_173 div E題   

#include <stdio.h>#include <algorithm>using namespace std;#define     LIMIT       45class Trie {    public :    Trie * children[2];    Trie () { children[0] = children[1] = NULL; }    void Insert(long long x, int deep)    {        if(deep == -1) return ;        int t = ((x >> deep) & 1LL);        if(!children[t]) children[t] = new Trie();        children[t]->Insert(x, deep-1);    }    long long Query(long long x, int deep)    {        if(deep == -1) return 0;        int t = (( x >> deep ) & 1LL);        if(children[!t]) return (1LL << deep) + children[!t]->Query(x, deep-1);        else return children[t]->Query(x, deep-1);        return 0;    }};Trie * root = new Trie();int n, m;int main(){    long long x;    scanf("%d%d", &n, &m);    for(int i = 0; i < n; i++) {        scanf("%lld", &x);        root->Insert(x, LIMIT);    }    long long ans = 0;    for(int i = 0; i < m; i++) {        scanf("%lld", &x);        ans = max(ans, root->Query(x, LIMIT));    }    printf("%lld\n", ans);    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.