C:
题意:
A 和 B玩游戏,A每次先手,游戏规则:在一个集合中找到两个数,他们的差绝对值不在集合中,则添加到集合里。如果无法选择了,那个人就是输了。
题解:
模拟不可能,这题找规律。
好吧,证明下面的结论也是无力。
所有初始数的最大公约数gcd,集合={1*gcd,2*gcd,…k*gcd≤max}max=所有初始数的最大值。
int gcd(int a, int b) {
if(b == 0)
return a;
return gcd(b, a % b);
}
这里贴一下gcd代码,自己写的就是垃圾。。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
int gcd(int x,int y){
if(x<y)
swap(x,y);
if(x%y==0){return y;}
else {
int temp=x;
x=y;
y=temp%y;
return gcd(x,y);
}
}
int main(){
int n;
cin>>n;
int num[105];
int maxn=-1;
for(int i=1;i<=n;i++){
cin>>num[i];
if(num[i]>maxn){maxn=num[i];}
}
int temp= gcd(num[1],num[2]);
for(int i=3;i<=n;i++){
temp=gcd(temp,num[i]);
}
if((maxn/temp-n)%2==0)cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
总结:第一次接触数论的题,这种“guess+几种样例观察结果”的方法,或许是一种可行的解法。。。