【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
5

Sample 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 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440229.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Apollo自动驾驶入门课程第⑧讲 — 规划(下)

目录 1. 路径-速度解耦规划 2. 路径生成与选择 3. ST图 4. 速度规划 5. 优化 6. 路径-速度规划的轨迹生成 7. Lattice规划 8. ST轨迹的终止状态 9. SL轨迹的终止状态 10. Lattice规划的轨迹生成 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿…

网络编程懒人入门(五):快速理解为什么说UDP有时比TCP更有优势

转自即时通讯网&#xff1a;http://www.52im.net/ 本文观点仅作参考&#xff0c;请根据自已系统的应用场景合理地选择数据传输层协议即可&#xff0c;无需盲目崇拜大牛言论。 1、前言 对于即时通讯开者新手来说&#xff0c;在开始着手编写IM或消息推送系统的代码前&#xff…

CSS定位总结:position=static/relative/absolute/fixed时的区别、top/bottom/left/right与margin外边距的运用

准备布局&#xff1a; <!DOCTYPE html> <html> <head> <style> *{ margin:0; padding:0; } .base-container{width: 500px;height: 500px;background-color:lightgray;border:1px dashed red; } .base-compare {width:200px;height:100px;background…

【HDU - 5883】The Best Path(判断欧拉回路)

题干&#xff1a; Alice is planning her travel route in a beautiful valley. In this valley, there are NN lakes, and MM rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up …

网络编程懒人入门(六):史上最通俗的集线器、交换机、路由器功能原理入门

转自即时通讯网&#xff1a;http://www.52im.net/ 本文引用了知乎网友“薛定谔不在家”的部分文字内容&#xff0c;感谢原作者的分享。 1、前言 即时通讯网整理了大量的网络编程类基础文章和资料&#xff0c;包括《TCP/IP协议 卷1》、《[通俗易懂]深入理解TCP协议》系列、《…

总结JSON.parse()报错VM71:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0等之类的问题

问题场景&#xff1a;在调试前端应用的时候经常出现形如“Uncaught SyntaxError: Unexpected”之类的令人头疼觉得莫名其妙的问题&#xff1b;所以有必要总结整理一下关于JSON.parse()这个API方法的注意事项。以便在以后的开发中出现类似的问题能第一时间想到可能是这个方法的参…

【HDU - 5884】Sort(k叉哈夫曼树,优化tricks,两个队列代替优先队列)

题干&#xff1a; Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from Alice. Alice will give Bob NN sorted sequences, and the ii-th sequence includes aiai elements. Bob need to merge all of these sequences. H…

金额输入框校验和自动校正、支持指定任意位数小数decimal、支持只能输入整数、支持是否允许输入负数等功能

应用场景&#xff1a;开发前端交互页面时&#xff0c;经常遇到金额输入框、指定小数位数的数字输入框&#xff0c;单一的正则表达式无法满足大部分的业务校验需求&#xff0c;下面总结一个实用巧妙而又灵活的把普通输入框变成自动校正输入框的解决方案&#xff1a; 数字&#…

网络编程懒人入门(七):深入浅出,全面理解HTTP协议

转自即时通讯网&#xff1a;http://www.52im.net/ 本文引用了自简书作者“涤生_Woo”的文章&#xff0c;内容有删减&#xff0c;感谢原作者的分享。 1、前言 HTTP&#xff08;全称超文本传输协议&#xff0c;英文全称HyperText Transfer Protocol&#xff09;是互联网上应用…

【HDU - 5889】Barricade(最短路+网络流,最小割)

题干&#xff1a; The empire is under attack again. The general of empire is planning to defend his castle. The land can be seen as NN towns and MM roads, and each road has the same length and connects two towns. The town numbered 11 is where generals cast…

SM4国密对称算法源码解析

最近在研究国密算法&#xff0c;主要分为&#xff1a;SM2、SM3、SM4。其中SM2为非对称加密算法&#xff0c;SM3为哈希摘要算法&#xff0c;SM4为对称加密算法。 1.在SM4算法源文件中主要有以下几个函数&#xff1a; void sm4_setkey_enc( sm4_context *ctx, unsigned char ke…

Mac系统容易忽视但很实用的命令整理

001.终端指定用哪个软件打开指定的文件 # open -a 实用哪个软件(软件名有空格需转义) 文件名路径 open -a /Applications/Google\ Chrome.app xx.html # 【tips:】由于先输入"open -a"后tab键自动补全容易卡死终端&#xff0c;所以推荐先输入"/App..."&a…

【HDU 4394】Digital Square(bfs,数位搜索,思维,数学)

题干&#xff1a; Given an integer N,you should come up with the minimum nonnegative integer M.M meets the follow condition: M 2%10 xN (x0,1,2,3....) Input The first line has an integer T( T< 1000), the number of test cases. For each case, each line…

SM4算法原理

前面的文章介绍了SM4算法的C语言实现&#xff0c;源码可见文章&#xff1a;SM4国密对称算法源码解析_10点43的博客-CSDN博客_sm4代码。 本文将会介绍SM4算法原理&#xff0c;这部分可能会比较枯燥&#xff0c;但数学要求也不是太高。 目录 1.概述 2. 参数产生 3. 轮函数 4…

webpack打包前端项目入门

前言&#xff1a;在开发过程中&#xff0c;利用webpack可以帮我们自动把ES6语法编译成低版本浏览器能解析的JavaScript代码。下面给出webpack打包前端项目入门案例。 [终端&#xff1a;进入项目所在目录] 1.初始化项目依赖&#xff1a; npm init -y 2.安装webpack-cli脚手架…

网络编程懒人入门(八):手把手教你写基于TCP的Socket长连接

转自即时通讯网&#xff1a;http://www.52im.net/ 本文原作者&#xff1a;“水晶虾饺”&#xff0c;原文由“玉刚说”写作平台提供写作赞助&#xff0c;原文版权归“玉刚说”微信公众号所有&#xff0c;即时通讯网收录时有改动。 1、引言 好多小白初次接触即时通讯&#xff…

【HihoCoder - 1502】最大子矩阵(二维前缀和,尺取)

题干&#xff1a; 给定一个NxM的矩阵A和一个整数K&#xff0c;小Hi希望你能求出其中最大&#xff08;元素数目最多&#xff09;的子矩阵&#xff0c;并且该子矩阵中所有元素的和不超过K。 Input 第一行包含三个整数N、M和K。 以下N行每行包含M个整数&#xff0c;表示A。 对…

Idea Spring Boot配置文件.yaml或.properties不能自动提示的有效解决办法

SpringBoot项目的配置文件.yaml/.yml/.properties文件编写的时候没有自动提示&#xff0c;网上的解决办法五花八门&#xff0c;不一定适合具体个人的IDE环境&#xff0c;下面总结一套能解决绝大部分情况的方案&#xff1a; 先给出能自动识别的图样&#xff1a; 步骤1&#xff…

[通俗易懂]深入理解TCP协议(上):理论基础

转自即时通讯网&#xff1a;http://www.52im.net/ 前言 TCP是一个巨复杂的协议&#xff0c;因为他要解决很多问题&#xff0c;而这些问题又带出了很多子问题和阴暗面。所以学习TCP本身是个比较痛苦的过程&#xff0c;但对于学习的过程却能让人有很多收获。关于TCP这个协议的细…

【POJ - 3616】Milking Time (贪心+dp)

题干&#xff1a; Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N-1) so that she produces as much milk as possible. …