MAGCARI

GAA

Feb 20th, 2023
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. /*
  2.     Task    : _example
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 20 February 2023 [21:36]
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. char ans;
  10. void play(int l,int r,int target,int k){
  11.     if(r-l+1 == 3){
  12.         if(target == l) ans = 'g';
  13.         else            ans = 'a';
  14.         return ;
  15.     }
  16.     int sz = (r-l+1 - (k+3)) / 2;
  17.     if(target <= l + sz - 1)                play(l,l+sz-1,target,k-1);
  18.     else if(target <= l + sz - 1 + (k+3)){
  19.         if(target == l + sz)    ans = 'g';
  20.         else                    ans = 'a';
  21.         return ;
  22.     }else{
  23.         play(l + sz + (k+3),r,target,k-1);
  24.     }
  25. }
  26. int main(){
  27.     cin.tie(0)->sync_with_stdio(0);
  28.     cin.exceptions(cin.failbit);
  29.     int target;
  30.     cin >> target;
  31.     int n = 3,k = 0;
  32.     while(n < target)   k++,n = (2*n) + (k+3);
  33.     play(1,n,target,k);
  34.     cout << ans << '\n';
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment