Bear with Candy

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/squidsss/article/details/102755775

【Problem Description】

Two bears like to eat candy, and candy also like to play the relevant game. Limak Bob and playing the following games: Limak eat a sugar, then Bob eat two, then three Limak eat, followed Bob eat four, and so on. If a bear turn to sugar, but he did not eat the eat so much sugar, it is lost. Limak A eat up candies (or will stomach pain), and Bob B eat up sweets. Who can win? Please name the winner of the output ( "Limak" or "Bob").

[Input form]

The first line of the input contains an integer T, representative of the number of test data sets. The next set of data is T. Each set of data only one row, comprising two integers A and B, representing the number of pieces of candy and Bob Limak eat up.

[Form] output

T output common line, the test data on behalf of each winner

[Sample input]

10
3 2
4 2
1 1
1 2
1 3
9 3
9 11
9 12
9 1000
8 11

[Sample output]
Bob
Limak
Limak
Bob
Bob
Limak
Limak
Bob
Bob
Bob

[Sample Description]

In the first set of data, Limak eat a candy, then Bob eat two, then the Limak eat three, but it has been unable to eat so much, so Bob wins.

In a second set of data, Bob turn when eating 4 eat sugar, so Limak win.

In the eighth set of data, turn Limak eat seven sugar when the going gets, so Bob wins.

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)   //进行n组循环和输出
	{
		int x,y,l=0,b=0,a=1;  //x,y分别是Limak和Bob可吃的糖果数
		cin>>x>>y;            //l和b为它们已吃的糖果数,a为轮数
		do
		{
			if(a==1) l=1;   //第一次Limak吃
			else            //此后奇数轮Limak吃偶数轮Bob吃
			{
				if(a%2==0) b=b+a;    //它们吃过的糖果数累积相加
				else l=l+a;
			}
			a++;                 //轮数加一
		}while(l<=x&&b<=y);      //Limak和Bob未吃至最大值则进行循环
		if(l>x) cout<<"Bob"<<endl;    //当一方吃过但另一方未吃过时表明次方输
		else cout<<"Limak"<<endl;
	}
	return 0;
 }

Guess you like

Origin blog.csdn.net/squidsss/article/details/102755775