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
题意:王子和侍卫一起去救公主,公主和强盗排成一排,给你这一排的总人数和公主的在这一排的第几个位置,侍卫和王子一个轮一个杀强盗,谁先到公主的位置谁和公主结婚
,规定侍卫先开始杀。每个人杀之前可以选择从左边还是从右边。
思路:这是一个博弈论的,谁先到公主旁边,谁就赢。仔细看一下数据范围,公主是不可能站在边上的,然后侍卫和王子在轮到自己杀的时候,可以随意选择左右边的。所以
除了公主(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"); } }