题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1846
Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫《勇敢者的游戏》(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻。 Input 输入数据首先包含一个正整数C(C<=100),表示有C组测试数据。 Output 如果先走的人能赢,请输出“first”,否则请输出“second”,每个实例的输出占一行。 Sample Input 2 23 2 4 3
扫描二维码关注公众号,回复:
3166089 查看本文章
Sample Output first second |
巴什博弈入门题:判断n=k(m+1)+c先手赢,否则后手赢;
ac:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
//#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<string>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
//#define mod 1e9+7
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// 水印
//std::ios::sync_with_stdio(false);
int main()
{
std::ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
if(n%(m+1))
cout<<"first"<<endl;
else
cout<<"second"<<endl;
}
}