Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)

This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.

The jury guessed some array aa consisting of 66 integers. There are 66 special numbers — 44, 88, 1515, 1616, 2323, 4242 — and each of these numbers occurs in aa exactly once (so, aa is some permutation of these numbers).

You don't know anything about their order, but you are allowed to ask up to 44 queries. In each query, you may choose two indices ii and jj (1i,j61≤i,j≤6, ii and jj are not necessarily distinct), and you will get the value of aiajai⋅aj in return.

Can you guess the array aa?

The array aa is fixed beforehand in each test, the interaction program doesn't try to adapt to your queries.

Interaction

Before submitting the answer, you may ask up to 44 queries. To ask a query, print one line in the following format: ?ijj, where ii and jjshould be two integers such that 1i,j61≤i,j≤6. The line should be ended with a line break character. After submitting a query, flush the output and read the answer to your query — one line containing one integer aiajai⋅aj. If you submit an incorrect query (or ask more than 44queries), the answer to it will be one string 0. After receiving such an answer, your program should terminate immediately — otherwise you may receive verdict "Runtime error", "Time limit exceeded" or some other verdict instead of "Wrong answer".

To give the answer, your program should print one line !a1a1 a2a2 a3a3 a4a4 a5a5 a6a6 with a line break in the end. After that, it should flush the output and terminate gracefully.

Example
input
Copy
16
64
345
672
output
Copy
? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42
Note

If you want to submit a hack for this problem, your test should contain exactly six space-separated integers a1a1, a2a2, ..., a6a6. Each of 66 special numbers should occur exactly once in the test. The test should be ended with a line break character.

鸣谢https://blog.csdn.net/b_r_e_a_d/article/details/81784223

代码

#include <cstdio>
#include <cstring>
#include<cmath>
#include<algorithm> 
#include<iostream>
using namespace std;
int a[10]={4,8,15,16,23,42},d[5];
int main() {
    for(int i=1;i<=4;i++)
    {
        printf("? %d %d\n",i,i+1);
         fflush(stdout);
         cin>>d[i];
    }
   do
   {
       if(a[1]*a[0]==d[1]&&a[2]*a[1]==d[2]&&a[3]*a[2]==d[3]&&a[4]*a[3]==d[4])
       break;
}while(next_permutation(a,a+6));
       printf("!");

   for(int i=0;i<6;i++)
   cout<<" "<<a[i];
  
    fflush(stdout);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hh13579/p/10873209.html