巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物, 规定每次至少取一个,最多取m个。最后取光者得胜。
n=(m+1)*r+s; s不为零是先手胜利
1846
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
if(n%(m+1)==0) cout<<"second"<<endl;
else cout<<"first"<<endl;
}
return 0;
}
2149
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m){
if(n<m){
cout<<n;
for(int i=n+1;i<=m;i++){
cout<<" "<<i;
}
cout<<endl;
}
else if(n%(m+1)==0) cout<<"none"<<endl;
else {
cout<<n%(m+1)<<endl;
}
}
return 0;
}
2147
画出PN图,
根据以下规则
* 必败点(P点) :前一个选手(Previous player)将取胜的位置称为必败点。
* 必胜点(N点) :下一个选手(Next player)将取胜的位置称为必胜点。
* 必败(必胜)点的属性:
* (1) 所有终结点是必败点(P点);
* (2) 从任何必胜点(N点)操作,至少有一种方法可以进入必败点(P点);
* (3)无论如何操作, 从必败点(P点)都只能进入必胜点(N点).
* 由上面的属性得到该题的算法:
* 步骤2: 将所有一步操作能进入必败点(P点)的位置标记为必胜点(N点)
* 步骤3:如果从某个点开始的所有一步操作都只能进入必胜点(N点) ,则将该点标记为必败点(P点) ;
* 步骤4: 如果在步骤3未能找到新的必败(P点),则算法终止;否则,返回到步骤2。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m&&n&&m){
if(n%2&&m%2) cout<<"What a pity!"<<endl;
else cout<<"Wonderful!"<<endl;
}
return 0;
}