标签:else 博弈 contain 技术分享 start cond col contains java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2947 Accepted Submission(s): 1609
题意:硬币围成一圈,编号1-n,每人每次最多取k个连续的硬币,给出n和k,问最后谁赢
题解:典型的对称博弈,当k==1时,就看n的奇偶,k>=2时,应用对称博弈:先手取完后,环变成了链,后手只要创建一个对称局势便可获得胜利,把这条链分成相等的链
k>=2时,后手一定可以创建出对称局势,此时后手必胜
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() { 4 int t; 5 while(~scanf("%d",&t)) 6 { 7 8 for(int i=1;i<=t;i++) 9 { 10 int n,k; 11 scanf("%d %d",&n,&k); 12 if(k>=n) 13 { 14 printf("Case %d: first\n",i); 15 }else 16 { 17 if(k==1) 18 { 19 if(n%2==0)printf("Case %d: second\n",i); 20 else printf("Case %d: first\n",i); 21 }else 22 { 23 printf("Case %d: first\n",i); 24 } 25 } 26 } 27 } 28 return 0; 29 }
标签:else 博弈 contain 技术分享 start cond col contains java
原文地址:https://www.cnblogs.com/fqfzs/p/9837608.html