交互题 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;
}

 

转载于:https://www.cnblogs.com/qingjiuling/p/11424670.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值