Problem E. Balanced Game (The 2016 ACM-ICPC Asia Qingdao Regional Contest, Online)

Problem E. Balanced Game
Time limit: 1s
Color of balloons: 32768K
Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultane-
ously 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
standard input standard output
3
2
3
5


Bad
Balanced
Balanced
 

1分析:

     n个状态的游戏,问是否为平衡游戏。题目中定义Balanced Game中每种状态胜率都是50% (ock-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% ),这是非常关键的一个信息。要想达到平衡状态,对于每一个玩家来说,他胜负的概率都为1/2。

   以n个人玩游戏为例:除去玩家自己,对于剩下的(n-1)人,玩家必须打败(n-1)/2,且又被(n-1)/2人打败,此时才将达到题目所说平衡状态。也就是(n-1)为偶数(n为奇数)的时候,游戏将处于平衡状态。

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
int main()
{
	cin>>n;
	int m;
	while(n--)
	{
		cin>>m;
		if(m%2==0)
		  cout<<"Bad"<<endl;
		else
		  cout<<"Balanced"<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/SSYITwin/article/details/81668996