题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1846
代码:
#include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define pf printf #define mem(a,b) memset(a,b,sizeof(a)) #define prime1 1e9+7 #define prime2 1e9+9 #define pi 3.14159265 #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define scand(x) scanf("%llf",&x) #define f(i,a,b) for(int i=a;i<=b;i++) #define scan(a) scanf("%d",&a) #define mp(a,b) make_pair((a),(b)) #define P pair<int,int> #define dbg(args) cout<<#args<<":"<<args<<endl; #define inf 0x7ffffff inline int read(){ int ans=0,w=1; char ch=getchar(); while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();} while(isdigit(ch))ans=(ans<<3)+(ans<<1)+ch-'0',ch=getchar(); return ans*w; } int n,m,t; const int maxn=1005; const ll mod=10000; int sg[maxn],s[maxn]; void getSG(){ mem(sg,0); for(int i=1;i<=n;i++){ mem(s,0); for(int j=1;j<=m&&i-j>=0;j++){ s[sg[i-j]]=1;//i的后继结点放到s中 } for(int j=0;j<=n;j++){ if(!s[j]){sg[i]=j;break;} } } } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); std::ios::sync_with_stdio(false); t=read(); while(t--){ n=read(),m=read(); getSG(); if(sg[n])cout<<"first\n"; else cout<<"second\n"; } }