Advertisement
Guest User

B

a guest
Sep 20th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. typedef unsigned long long int ull;
  5. typedef long double ld;
  6.  
  7. ll mod = 1e9+7;
  8. const double error = 1e-7;
  9. const double PI = acos(-1); //const ld PI = acosl(-1)
  10.  
  11. #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
  12. #define eq(x, y) (fabs((x)-(y))<error)
  13. #define bt(i) (1LL<<(i))
  14.  
  15. #define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
  16. #define hoise cerr<<"hoise\n"
  17. #define tham getchar()
  18. mt19937_64 rng((unsigned int) chrono::system_clock::now().time_since_epoch().count());
  19.  
  20. inline ll MOD(ll x, ll m = mod)
  21. {
  22.     ll y = x % m;
  23.     return (y >= 0) ? y: y+m;
  24. }
  25.  
  26. const int inf = 1e8+5;
  27. const ll infl = 1e15;
  28. const int nmax = 1e5+5;
  29. const int nmax2 = 1e7+5;
  30. ///====================== template =========================
  31.  
  32. int grundystone[nmax2];
  33. int grundypile[nmax];
  34. void precal(){
  35.     for(int i = 2; i<nmax2; i++){
  36.         int j;
  37.         if(i%7 == 0) j = i/7;
  38.         else if(i % 4 == 0) j = i/4;
  39.         else j = i/3;
  40.         if(j < 3) grundystone[i] = 0;
  41.         else grundystone[i] = grundystone[j]^1;
  42.     }
  43.  
  44.     for(int i = 1; i<nmax; i++){
  45.         if(i == 4 || i == 7) grundypile[i] = -1;
  46.         else{
  47.             vector<int> v;
  48.             if(i-4>0) v.push_back(grundypile[i-4]);
  49.             if(i-7>0) v.push_back(grundypile[i-7]);
  50.             sort(v.begin(), v.end());
  51.             int ret = 0;
  52.             for(int x: v) if(ret == x) ret++;
  53.             grundypile[i] = ret;
  54.         }
  55.     }
  56. }
  57.  
  58. int G(int x){
  59.     if(x < nmax2) return grundystone[x];
  60.     if(x % 7 == 0) return G(x/7)^1;
  61.     else if(x % 4 == 0) return G(x/4)^1;
  62.     else return G(x/3)^1;
  63. }
  64.  
  65. int main(){
  66.     FASTIO;
  67.     precal();
  68.  
  69.     //for(int i = 0; i<20; i++) {debug(i);debug(grundystone[i]);}
  70.  
  71.     int tc;
  72.     cin>>tc;
  73.     for(int cs = 1; cs<=tc; cs++){
  74.         int n, m;
  75.         cin>>n>>m;
  76.         if(n == 4 || n == 7 || m == 1 || m == 2){
  77.             cout<<"Case "<<cs<<": Alice\n";
  78.             continue;
  79.         }
  80.  
  81.         int x = grundypile[n] ^ G(m);
  82.         cout<<"Case "<<cs<<": ";
  83.         if(x ==  0) cout<<"Bob\n";
  84.         else cout<<"Alice\n";
  85.  
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement