1. 程式人生 > >Yet Another Game of Stones ZOJ - 3964

Yet Another Game of Stones ZOJ - 3964

情況

  1. 如果B[i]==2 ,但A[i] %2 ==1 ,對於Alice來說肯定沒法取完,所以必輸
  2. 考慮B[i] == 1,B[i] == 2,這兩種情況,如果B[i]==1,A[i] == 1,這就相當於nim博弈了,如果B[i]==1&A[i] >1的個數加上B[i] ==2 &&B[i] > 1的個數大於等於2,那麼這種情況無論nim_sum ==0 ,或者不等於零,都是必輸的
  3. 如果B[i] == 1&&A[i] > 1的個數為1,那麼肯定要先取這個,考慮取奇數個之後的nim值
  4. 如果B[i] == 2&&A[i] > 1的個數為1,那麼肯定要取完,考慮剩下來的nim值
  5. 其他情況退化成nim博弈
const int maxn = 1e6+100;

int A[maxn];
int B[maxn];
  int n,T;

bool solve(){
    scanf("%d",&n);
    int sum = 0;
    int c1 = 0,c2 =0;
    rep(i,0,n) scanf("%d",&A[i]),sum ^= A[i];
    rep(i,0,n) {
      scanf("%d",&B[i]);
     
    }
    rep(i,0,n){
      if(B[i] ==2 &&
A[i] %2 ==1) return 0; if(B[i] == 1&&A[i] > 1) c1++; if(B[i] == 2&&A[i] > 1) c2++; } if(c1 +c2 > 1) return 0; if(c1 == 1){ // for(auto c:) rep(i,0,n) { if(A[i] > 1&&B[i] == 1){ sum ^= A[i]; sum ^
= (A[i]%2==0); return !sum; } } } if(c2 == 1){ rep(i,0,n){ if(A[i] > 1&&B[i] == 2){ sum ^= A[i]; return !sum; } } } return sum; } int main(void) { cin>>T; while(T--){ printf("%s\n", solve() ? "Alice" : "Bob"); } return 0; }