剩下的人数之和为奇数时先手胜,否则后手胜。
考虑最后一步
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 //ios_base::sync_with_stdio(0); 6 int n, k; 7 while(cin>>n>>k){ 8 int cnt = 0; 9 int x; 10 long long sum = 0; 11 for(int i = 0; i < n; i++){ 12 scanf("%d", &x); 13 sum = sum + x; 14 if(x & 1) cnt++; 15 } 16 int ok = 1; 17 if(n == k){ 18 if(sum & 1) ok = 1; 19 else ok = 0; 20 }else{ 21 int m = n - k, op = m / 2; 22 if(m & 1) { // 先手最后拿 23 if(k & 1){ 24 if(op >= cnt) ok = 0; 25 else ok = 1; 26 }else{ 27 if(op >= cnt || op >= (n - cnt)) ok = 0; 28 else ok = 1; 29 } 30 }else { 31 if(k & 1){ 32 if(op >= (n - cnt)) ok = 1; 33 else ok = 0; 34 }else{ 35 ok = 0; 36 } 37 } 38 } 39 if(ok) cout<<"Stannis "; 40 else cout<<"Daenerys "; 41 } 42 }
取石子游戏
链接:here