【HDU - 5882】Balanced Game (找规律,思维)
題干:
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%50%?no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer?NN, 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)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
3 2 3 5Sample Output
Bad Balanced Balanced題目大意:
剪刀石頭布(這三種操作)會使得每個人都有50%的勝率(如果兩人操作相同則重新這一回合)
現在已知有n種操作,問這n種操作能否使得每種操作的勝率為50%。
解題報告:
如果把操作看成點,之間的關系看成邊,那么在剩余n-1個頂點中需要有一半指向自己,一半由自己指向,所以n-1需要是偶數,n需要是奇數,由此得到了一個可以輸出Balanced的必要條件(也就是如果要是Balance的,那就必須n是奇數)。
現在來證明n是奇數,那么一定能構造出來一個Balance的解,也就是充分條件(wjh大佬tql)。(因為每兩個頂點之間只能有一條有向邊(因為不可能我比你強的同時你也比我強)所以有可能構造不出來,所以需要證明一定可以構造出來)對于n個操作的,自然不好構造,但是我們可以用數學歸納法類似的思想,由小及大。對于三個操作的,比如石頭剪刀布,一定可以構造吧,然后在此基礎上加兩個頂點,那么這兩個頂點和那三個頂點之間沒有任何關系(可以隨意連邊),所以我們:這兩個頂點之間連一條邊(誰到誰的都行),然后這兩個點和剩下的頂點根據情況連邊一定可以構造出來。以此往復,就可以構造出來任意奇數個操作的可行解了。重點就是已知三個點是可以構造的,然后依次加兩個點也能構造,然后就可以證明了。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5;int main() {int t,n;cin>>t;while(t--) {scanf("%d",&n);if(n % 2 == 1) {puts("Balanced");}else puts("Bad");}return 0 ; }?
總結
以上是生活随笔為你收集整理的【HDU - 5882】Balanced Game (找规律,思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: “路由器之王”思科正式退出俄罗斯市场
- 下一篇: 【牛客 - 696C】小w的禁忌与小G的
