Advertisement
Korotkodul

CF D 7

Aug 15th, 2022 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) {
  18.             cout<<x<<' ';
  19.     }
  20.     cout<<"\n";
  21. }
  22.  
  23. void cvl(vector <ll> &v){
  24.     for (auto x: v) cout<<x<<' ';
  25.     cout<<"\n";
  26. }
  27.  
  28.  
  29. void cvv(vector <vector <int> > &v){
  30.     for (auto x: v) cv(x);
  31.     cout<<"\n";
  32. }
  33.  
  34. void cvb(vector <bool> v){
  35.     for (bool x: v) cout<<x<<' ';
  36.     cout<<"\n";
  37. }
  38.  
  39. void cvs(vector <string>  v){
  40.     for (auto a: v){
  41.         cout<<a<<"\n";
  42.     }
  43. }
  44.  
  45. void cvp(vector <pii> a){
  46.     for (auto p: a){
  47.         cout<<p.first<<' '<<p.second<<"\n";
  48.     }
  49.     cout<<"\n";
  50. }
  51.  
  52.  
  53. bool sh=1;
  54.  
  55. int n, N;
  56.  
  57. // n = 1 - отдельно
  58.  
  59. void ask(int a, int b){
  60.     cout<<"? "<< (a)<<' '<<(b)<<"\n";
  61.     //cout.flush();
  62. }
  63.  
  64. void slv(){
  65.     vector <int> a,b;
  66.     for (int i = 1; i <= pow(2,n); ++i){
  67.         a.push_back(i);
  68.     }
  69.  
  70.     while (a.size() >= 4){
  71.         if (sh){
  72.             cout<<"a\n";
  73.             cv(a);
  74.         }
  75.         n = a.size();
  76.         for (int i = 0; i + 3 < n; i+=4){
  77.             if (sh){
  78.                 cout<<"i = "<<i<<"\n";
  79.                 cout<<"a\n";
  80.                 cv(a);
  81.             }
  82.             ask(a[i], a[i+2]);
  83.             int r;
  84.             cin>>r;
  85.             int w1, w2, w;
  86.             if (r == 0){
  87.                 w1 = a[i+1];
  88.                 w2 = a[i + 3];
  89.             }
  90.             else if (r == 1){
  91.                 w1 = a[i];
  92.                 w2 = a[i + 3];
  93.             }
  94.             else if (r == 2){
  95.                 w1 = a[i + 1];
  96.                 w2 = a[i + 2];
  97.             }
  98.             w = w1;
  99.             ask(w1, w2);
  100.             cin>>r;
  101.             if (r == 2){
  102.                 w = w2;
  103.             }
  104.             b.push_back(w);
  105.             a = b;
  106.             b.clear();
  107.             if (sh){
  108.  
  109.             }
  110.         }
  111.     }
  112.     ask(a[0], a[1]);
  113.     int r; cin>>r;
  114.     if (r == 1){
  115.         cout<<a[0]<<"\n";
  116.     }
  117.     else{
  118.         cout<<a[1]<<"\n";
  119.     }
  120. }
  121.  
  122. int main()
  123. {
  124.     /*ios::sync_with_stdio(0);
  125.     cin.tie(0);
  126.     cout.tie(0);*/
  127.     int t=1;
  128.     if (!sh) cin>>t;
  129.     for (int go = 0; go < t; ++go){
  130.         cin>>n;
  131.         slv();
  132.     }
  133. }
  134. /*
  135. 1
  136. 3
  137. ? 1 3
  138. 0
  139. ? 1 4
  140. 1
  141. ? 5 7
  142. 0
  143. ? 5 8
  144. 2
  145.  
  146.  
  147. ? 1 0
  148. */
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement