zstu 4238 Save the Princess(2016新生赛)

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

题意:王子和侍卫一起去救公主,公主和强盗排成一排,给你这一排的总人数和公主的在这一排的第几个位置,侍卫和王子一个轮一个杀强盗,谁先到公主的位置谁和公主结婚

,规定侍卫先开始杀。每个人杀之前可以选择从左边还是从右边。

思路:这是一个博弈论的,谁先到公主旁边,谁就赢。仔细看一下数据范围,公主是不可能站在边上的,然后侍卫和王子在轮到自己杀的时候,可以随意选择左右边的。所以

除了公主(n-1)个人,侍卫先开始,那如果(n-1)是奇数,只剩公主时轮到侍卫,(n-1)是偶数的时候,只剩公主的时候轮到王子。

代码: #include<iostream> #include<cstdio> using namespace std; int main() {   int t;   long long n,k;   scanf("%d",&t);   while(t--)   {     scanf("%lld%lld",&n,&k);      if((n-1)%2!=0) printf("LYF\n"); else  printf("BH\n");   } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值