题目描述:

题目链接
Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are “rock”, “paper”, and “scissors”. The game has only three possible outcomes other than a tie: a player who decides to play rock will beat another player who has chosen scissors (“rock crushes scissors”) but will lose to one who has played paper (“paper covers rock”); a play of paper will lose to a play of scissors (“scissors cut paper”). If both players choose the same shape, the game is tied and is usually immediately replayed to break the tie.

Recently, there is a upgraded edition of this game: rock-paper-scissors-Spock-lizard, in which there are totally five shapes. The rule is simple: scissors cuts paper; paper covers rock; rock crushes lizard; lizard poisons Spock; Spock smashes scissors; scissors decapitates lizard; lizard eats paper; paper disproves Spock; Spock vaporizes rock; and as it always has, rock crushes scissors.

Both rock-paper-scissors and rock-paper-scissors-Spock-lizard are balanced games. Because there does not exist a strategy which is better than another. In other words, if one chooses shapes randomly, the possibility he or she wins is exactly 50% no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer N, representing the count of shapes in a game. You need to find out if there exist a rule to make this game balanced.

Input

The first line of input contains an integer t, the number of test cases. t test cases follow.
For each test case, there is only one line with an integer N (2≤N≤1000), as described above.

Here is the sample explanation.

In the first case, donate two shapes as A and B. There are only two kind of rules: A defeats B, or B defeats A. Obviously, in both situation, one shapes is better than another. Consequently, this game is not balanced.

In the second case, donate two shapes as A, B and C. If A defeats B, B defeats C, and C defeats A, this game is balanced. This is also the same as rock-paper-scissors.

In the third case, it is easy to set a rule according to that of rock-paper-scissors-Spock-lizard.

Output

For each test cases, output “Balanced” if there exist a rule to make the game balanced, otherwise output “Bad”.

Sample Input

1
2
3
4
3
2
3
5

Sample Output

1
2
3
Bad
Balanced
Balanced

题解

首先说这是很水的一道题, 我是到最后才看清题意,Given an integer N, representing the count of shapes in a game.本来我是以为只有石头剪刀布还有5种shape这两种玩法, 然后就各种对5对3取余。。。。后来发现大错特错。
题意: 给你n种shape, 让你判断是不是平衡的。何谓平衡? 这是重点。
举几个例子你就明白了。
当n = 2 时, 两个shape, 对于每个shape, 只有一个出边, 或者入边, 这就是不平衡。
当n = 3 时, 三个shape, 对于每个shape, 他会有两个边, 一个入边一个出边(想想三角形就明白了, 至于入边和出边, 画了图, 就明白了了), 这就是平衡(入边数和出边数相同)。
当n = 4 时, 四个shape, 对于每个shape, 他会有三个边, 那就只有两种情况 2个入边1个出边 和 2个出边1个入边 , 这明显是不平衡的。
当n = 5 时, 五个shape, 对于每个shape, 他会有四个边, 两个入边两个出边, 所以是平衡的。

好了, 规律就有了:
当n为奇数时, 平衡。
当n为偶数时, 不平衡。

AC代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include "algorithm"
#include "cstdio"
#include "queue"
#include "set"
#include "cstring"
#include "string"
#include "map"
#include "vector"
#include "math.h"
#include "utility" // pair头文件
#define esp 1e-6
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;


int main(){
ios::sync_with_stdio(0);
int t, n;
cin >> t;
while(t--){
cin >> n;
if (n % 2 == 1)
puts("Balanced");
else
puts("Bad");
}
}
1
恰似你一低头的温柔,娇弱水莲花不胜寒风的娇羞, 我的心为你悸动不休。  --mingfuyan