8 条题解

  • 0
    @ 2023-7-7 16:32:00
    #include <iostream>
    
    using namespace std;
    int rec[10000005][2];
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int amount, n;
        int cnt = 0;
        cin >> amount;
    
        int result = 0;
        for (int i = 0; i < amount; i++) {
            cin >> n;
            int insert_p = 0;
            int search_p = 0;
            int val = 0;
            int bits = 30;
            while (bits >= 0) {
                int head = n >> bits & 1;
                if (rec[insert_p][head] == 0) {
                    rec[insert_p][head] = ++cnt;
                }
                insert_p = rec[insert_p][head];
    
                if (rec[search_p][1 - head] != 0) {
                    search_p = rec[search_p][1 - head];
                    val += 1 << bits;
                } else {
                    search_p = rec[search_p][head];
                }
                bits--;
            }
            if (val > result) { result = val; }
        }
    
        cout << result;
        return 0;
    }
    

    insert 和 search 可以一个循环一起完成

    信息

    ID
    94
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    740
    已通过
    174
    上传者