• 交互题 XOR Guessing


    题目链接:https://www.luogu.org/problem/CF1207E

    题意:有一个数x(0-2^14-1),让你猜,你每次会提出两个询问,每次询问包含100个整数(这两百个整数必须不同),然后每次会给你两个输入,分别是数x异或询问中的某一个数的结果,求x

    分析:设每次挑选到的两个数为A,B,返回的结果是C,D。那么就要A^X=C,B^X=D.即A^B=C^D

    只要求出A和B的任一个,带进前两个式子就可以求结果了

    故我们需要构造这样的两个序列,满足A,B两两配对形成的A^B的结果都是不同的

    最简单的就是A在1,2,3...100,B在2^7,2*2^7...100*2^7.这种情况下两者没有重叠的位数,A^B即A+B

    剩下的直接看代码了,关于刷新输出要注意

    #include <bits/stdc++.h>
    #define _rep(i, x, y) for(int i = x; i <= y; i++)
    #define _per(i, x, y) for(int i = x; i >= y; i--)
    #define LL long long
    using namespace std;
    template <typename T>
    inline void read(T &x) {
        x = 0;
        LL f = 1;
        char c = getchar();
        for (; !isdigit(c); c = getchar())
            if (c == '-')
                f = -1;
        for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
        x *= f;
    }
    template <typename T>
    inline void write(T x) {
        if(x < 0) {putchar('-'); x = -x;}
        if(x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
    int a[101], b[101], x;
    int main() {
        _rep(i, 1, 100) {
            a[i] = i;
            b[i] = (i << 7);
        }
        cout << "?";
        _rep(i, 1, 100) {
            cout << " " << a[i];
        }
        cout << endl;
        fflush(stdout);
        int c; cin >> c;
        cout << "?";
        _rep(i, 1, 100) {
            cout << " " << b[i];
        }
        cout << endl;
        fflush(stdout);
        int d; cin >> d;
        int b = (c ^ d) >> 7;
        cout << "! " << ((b << 7) ^ d) << endl; 
        return 0;
    }
  • 相关阅读:
    关于MapReduce中自定义分区类(四)
    关于MapReduce中自定义分组类(三)
    UiAutomator2.0
    Java_集合框架
    Python爬取指定重量的快递价格
    Java_面向对象
    Java_异常以及处理
    Java_File类
    Java_Scanner和System类
    Java_Runtime&Process&ProcessBuilder
  • 原文地址:https://www.cnblogs.com/qingjiuling/p/11424670.html
Copyright © 2020-2023  润新知