There were N people standing in a row, including the princess and N-1 robbers,numbered 1 to N from left to right. You already know the princess’ number is K. BH and LYF must kill robbers before meeting the princess. BH and LYF were both very powerful, they took turns killing the robbers. On each turn, a man could kill the left most robber or kill the right most robber. The massacre would end until there was a man to save the princess. The princess would marry the man who saved her first. Assume that BH and LYF kill optimally and LYF kill first, determine the princess would be married to who.
Input
The first line of the input contains an integer T(T <= 500) which means the number of test cases.
For each test case, there are two integers n(3 <= n <= 1000000000) and k(1 < k < n) which mean the number of robbers and the princess’ position.
Output
Output a single line: if the princess would be married to the prince, print ”BH”(without quote), otherwise print ”LYF”(without quote).
Sample Input
5 3 2 4 3 5 2 6 4 6 5
Sample Output
BH LYF BH LYFLYF
#include<cstring> #include<cstdio> #include<iostream> using namespace std; int main(){ int t; cin>>t; while(t--) { int n,k; cin>>n>>k; printf("%s\n",n&1?"BH":"LYF"); } } #include<bits/stdc++.h> const int N=1e3+5; int sg[N][N]; bool vis[N]; int SG(int x,int y) { if(sg[x][y]!=-1) return sg[x][y]; int a=-1,b=-1; if(x>1) a=SG(x-1,y); if(y>1) b=SG(x,y-1); int vis[2]={0}; if(a!=-1) vis[a]=true; if(b!=-1) vis[b]=true; int ret=0; while(vis[ret]) ret++; return sg[x][y]=ret; } int main(){ memset(sg,-1,sizeof(sg)); sg[1][1]=0; int t; scanf("%d",&t); while(t--) { int n,k; scanf("%d%d",&n,&k); printf("%s\n",SG(k-1,n-k)?"LYF":"BH"); } }