Codeforces Round #525 (Div. 2) D(交互题+思维)

D. Ehab and another another xor problem

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This is an interactive problem!

Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b)(a,b). Laggy can ask a pair of integers (c,d)(c,d) and Ehab will reply with:

  • 1 if a⊕c>b⊕da⊕c>b⊕d.
  • 0 if a⊕c=b⊕da⊕c=b⊕d.
  • -1 if a⊕c<b⊕da⊕c<b⊕d.

Operation a⊕ba⊕b is the bitwise-xor operation of two numbers aa and bb.

Laggy should guess (a,b)(a,b) with at most 62 questions. You'll play this game. You're Laggy and the interactor is Ehab.

It's guaranteed that 0≤a,b<2300≤a,b<230.

Input

See the interaction section.

Output

To print the answer, print "! a b" (without quotes). Don't forget to flush the output after printing the answer.

Interaction

To ask a question, print "? c d" (without quotes). Both cc and dd must be non-negative integers less than 230230. Don't forget to flush the output after printing any question.

After each question, you should read the answer as mentioned in the legend. If the interactor replies with -2, that means you asked more than 62 queries and your program should terminate.

To flush the output, you can use:-

  • fflush(stdout) in C++.
  • System.out.flush() in Java.
  • stdout.flush() in Python.
  • flush(output) in Pascal.
  • See the documentation for other languages.

Hacking:

To hack someone, print the 2 space-separated integers aa and bb (0≤a,b<230)(0≤a,b<230).

Example

input

Copy

1
-1
0

output

Copy

? 2 1
? 1 2
? 2 0
! 3 1

Note

In the sample:

The hidden numbers are a=3a=3 and b=1b=1.

In the first query: 3⊕2=13⊕2=1 and 1⊕1=01⊕1=0, so the answer is 1.

In the second query: 3⊕1=23⊕1=2 and 1⊕2=31⊕2=3, so the answer is -1.

In the third query: 3⊕2=13⊕2=1 and 1⊕0=11⊕0=1, so the answer is 0.

Then, we printed the answer.

题意:小A有两个数a和b 你去猜 你每次可以给出两个数 c和d  

  • 1 if a⊕c>b⊕da⊕c>b⊕d.
  • 0 if a⊕c=b⊕da⊕c=b⊕d.
  • -1 if a⊕c<b⊕da⊕c<b⊕d.

最多猜不超过62次

题解:神奇的交互题 还是第一次做这种题 系统根据你的输入返回值 对于这道题来说 可以每次确定每一位上a和b的关系来确定每一位数 同时防止前面的数造成的影响 将前面两个数字都不同的那一位保存下来 最后输出答案即可

#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=998244353;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c))c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()

int Sheryang()
{
    printf("? 0 0\n");
    fflush(stdout);
    int ot;
    scanf("%d",&ot);
    int nowa=0,nowb=0;
    int ansa=0,ansb=0;

    for(int i=29;i>=0;i--){
        int now=1<<i;
        if(ot==0){
            printf("? %d %d\n",now+nowa,nowb);
            int ot2;
            fflush(stdout);
            scanf("%d",&ot2);
            if(ot2==-1){
                ansa+=now;
                ansb+=now;
            }
            continue;
        }
        printf("? %d %d\n",now+nowa,now+nowb);
        int ot2;
        fflush(stdout);
        scanf("%d",&ot2);
        if(ot==1){
            if(ot2==1){
                printf("? %d %d\n",now+nowa,nowb);
                int ot3;
                fflush(stdout);
                scanf("%d",&ot3);
                if(ot3==-1){
                    ansa+=now;
                    ansb+=now;
                }
            }else{
                ansa+=now;
                nowa+=now;
                printf("? %d %d\n",nowa,nowb);
                fflush(stdout);
                scanf("%d",&ot);
                continue;
            }
        }else{
            if(ot2==-1){
                printf("? %d %d\n",now+nowa,nowb);
                int ot3;
                fflush(stdout);
                scanf("%d",&ot3);
                if(ot3==-1){
                    ansa+=now;
                    ansb+=now;
                }
            }else{
                ansb+=now;
                nowb+=now;
                printf("? %d %d\n",nowa,nowb);
                fflush(stdout);
                scanf("%d",&ot);
                continue;
            }
        }
    }
    printf("! %d %d\n",ansa,ansb);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sudu6666/article/details/85391924