D1. RPD and Rap Sheet (Easy Version) (交互题+构造)

题意:

交互题,有一个初始密码 x x x,只有 n n n次猜测机会,假如猜了 y y y x ! = y x!=y x!=y,那么密码就会变成 x ⨁ y x\bigoplus y xy

题解:

设第 i i i次猜测的数为 p i p_i pi,那么令 p i = ( i − 1 ) ⨁ ( i − 2 ) p_i=(i-1) \bigoplus (i-2) pi=(i1)(i2) ,特别的, p 1 = 0 p_1=0 p1=0 。那么每次猜测完之后,密码的变换就有如下规律:

0 ⨁ x 0\bigoplus x 0x

1 ⨁ x 1\bigoplus x 1x

2 ⨁ x 2\bigoplus x 2x

3 ⨁ x 3\bigoplus x 3x

. . . . . . ...... ......

所以第 x x x次猜测后,密码会变为 ( x − 1 ) ⨁ x (x-1)\bigoplus x (x1)x ,而第 x + 1 x+1 x+1 p x + 1 = ( x − 1 ) ⨁ x p_{x+1}=(x-1)\bigoplus x px+1=(x1)x 因此可以猜到。

代码:

#pragma GCC diagnostic error "-std=c++11"
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<ctime>
#define iss ios::sync_with_stdio(false)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const int MAXN=2e5+5;
const int inf=0x3f3f3f3f;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,k,x;
        cin>>n>>k;
        for(int i=0;i<=n-1;i++){
            if(i==0)
            {
                cout<<i<<endl;
            }
            else 
            {
                cout<<(i^(i-1))<<endl;
            }
            cin>>x;
            if(x==1)
            {
                break;
            }
        }
    }    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值