4238: Save the Princess 博弈

Once upon time there was a cute princess called JW living in a castle. One day, the princess had been kidnapped by the robbers. The prince called BH became worried, he wanted to save the princess. So the prince BH and a soldier called LYF went to save the princess. 
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
LYF

LYF

#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"); } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值