game theory博弈论全文翻译_john nash博弈论

game theory博弈论全文翻译_john nash博弈论ProblemDescriptionLittleJohnisplayingveryfunnygamewithhisyoungerbrother.ThereisonebigboxfilledwithM&Msofdifferentcolors.AtfirstJohnhastoeatseveralM&Msofthesamecolor

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

Problem Description
Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so on. Please note that each player has to eat at least one M&M during his turn. If John (or his brother) will eat the last M&M from the box he will be considered as a looser and he will have to buy a new candy box.

Both of players are using optimal game strategy. John starts first always. You will be given information about M&Ms and your task is to determine a winner of such a beautiful game.

Input
The first line of input will contain a single integer T – the number of test cases. Next T pairs of lines will describe tests in a following format. The first line of each test will contain an integer N – the amount of different M&M colors in a box. Next line will contain N integers Ai, separated by spaces – amount of M&Ms of i-th color.

Constraints:
1 <= T <= 474,
1 <= N <= 47,
1 <= Ai <= 4747

Output
Output T lines each of them containing information about game winner. Print “John” if John will win the game or “Brother” in other case.
Sample Input
233 5 111
 

 

Sample Output
John
Brother

这一题有点类似于NIM游戏,当符合一定条件的时候,先手可必胜。

这里用到了一个规律。把每一堆的数目进行异或运算(每一堆的数目都是1除外),

最后的结果有两种,为0或不为0,若为0则各堆的二进制位相加不进位以后所得到

的数的各位数一定是一个偶数。我们称结果为0的情况为平衡状态,如果刚开始局

面是一个不平衡状态,即各堆的各位二进制数的和不全为偶数,可判定为先手的必胜残局。

 

举个例子:

下面应用此获胜策略来考虑4-堆的Nim取子游戏。其中各堆的大小分别

791215枚硬币。用二进制表示各数分别为:0111100111001111

于是可得到如下一表:

大小为7的堆  0 1 1 1

大小为9的堆  1 0 0 1

大小为12的堆 1 1 0 0

大小为15的堆 1 1 1 1

 

Nim取子游戏的平衡条件可知,此游戏是一个非平衡状态的取子游戏,因此,

游戏人I在按获胜策略进行取子游戏下将一定能够取得最终的胜利。具体做法

有多种,游戏人I可以从大小为12的堆中取走11枚硬币,使得游戏达到平衡(如下表),

 

大小为7的堆  0 1 1 1

大小为9的堆  1 0 0 1

大小为12的堆 0 0 0 1

大小为15的堆 1 1 1 1

 

之后,无论游戏人II如何取子,游戏人I在取子后仍使得游戏达到平衡。

同样的道理,游戏人I也可以选择大小为9的堆并取走5枚硬币而剩下4枚,

或者,游戏人I从大小为15的堆中取走13枚而留下2枚。

归根结底,Nim取子游戏的关键在于游戏开始时游戏处于何种状

态(平衡或非平衡)和第一个游戏人是否能够按照取子游戏的获胜策略来进行游戏。

 

做这题很容易被英文描述给弄晕,说白了就是这你懂不懂这个游戏,可是

文章却描述的很烂不知道在说什么,做了好些英文题感觉这种题目挺多的,

这种题目指定要靠你什么知识定理什么的,要是之前做过,那么就会容易理解

题意,那么完成这题也就是不需要理会它题目是怎么描述的了……

 

 

下面补充下:

 

§

下面再举一例子:来自北大oj,http://acm.pku.edu.cn/JudgeOnline/problem?id=1704

Description

Georgia and Bob decide to play a self-invented game. They draw a row of
grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N
chessmen on different grids, as shown in the following figure for example:

Georgia and Bob move the chessmen in turn. Every time a player will choose a
chessman, and move it to the left without going over any other chessmen or across the left
edge. The player can freely choose number of steps the chessman moves, with the
constraint that the chessman must be moved at least ONE step and one grid can at
most contains ONE single chessman. The player who cannot make a move loses the game.

Georgia always plays first since "Lady first". Suppose that Georgia and Bob both do
their best in the game, i.e., if one of them knows a way to win the game, he or she will
be able to carry it out.

Given the initial positions of the n chessmen, can you predict who will finally win the game?

Input

The first line of the input contains a single integer T (1 <= T <= 20), the number of test
cases. Then T cases follow. Each test case contains two lines. The first line consists
of one integer N (1 <= N <= 1000), indicating the number of chessmen. The second line
contains N different integers P1, P2 ... Pn (1 <= Pi <= 10000), which are the initial
positions of the n chessmen.

Output

For each test case, prints a single line, "Georgia will win",
if Georgia will win the game; "Bob will win", if Bob will win the game;
otherwise 'Not sure'.

Sample Input

2
3
1 2 3
8
1 5 6 7 9 12 14 17

Sample Output

Bob will win
Georgia will win
这题的思想就是把它转换成博弈思想,和上面的吃糖那题类似。这种就是石头有多堆的情况,而下面
讲的取石游戏是一堆的情况。这种类型的题目运用比较广,叫 尼姆博弈……
 
        
        
        
§ 这题我们还是可以通过转化成尼姆博弈来求解。
§ 通过两两配对做成堆
§ 如何分堆
§ 如果偶数个(1.2,34,……n-1n);
§
§ 设各堆中的间隔为a1a2a3……an
§ s=a1^a2&^a3…….^an
§ 判断s是否为0
奇数时则需在左边添加一个与第一个配对,之后一样两两配对

 

巴什博弈:两人取石头游戏

石头总数为n,每人每次最少取1个,最多取m个,最后取完者胜。

§

 
当n%m+1)=s时不等于0.
我第一次取s个。
从现在开始,我只要每次拿的个数与前面另一个人拿的个数和等m+1


其实我们只需要判断n%m+1)是否等于0可知道谁胜谁负。

§
到最后另一个拿的时候肯定是剩tt<m个给我,傻瓜也知道我赢了,嘿嘿!


用个例子来说,假设n=k*m+1+s,那我先把那个S个拿掉,然后让另外一个人拿,

如:

§假设有66个石头,我们每次最多拿6个,则mod667=3

§
第一次:3    1          62
§
第二次:6    2          54
§
第三次:5    4          45
§
第四次:3    2          40
§
第五次:5    6          29
§
第六次:1    5          23
§
第七次:2    6          15
§
第八次:1    5           9
§
第九次:2    6           1
§
第十次:1                 0

 

§
当然我也有输的情况,那就是n=k*m+1)=0时,而另外一个人每次都拿(m+1)减我拿的个数

 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/189553.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 开发大数据基础教程(前端开发入门)

    第一阶段linux+搜索+hadoop体系第一阶段:linux+搜索+hadoop体系Linux大纲这章是基础课程,帮大家进入大数据领域打好Linux基础,以便更好地学习Hadoop,hbase,NoSQL,Spark,Storm,docker,kvm,openstack等众多课程。因为企业中无一例外的是使用Linux来搭建或部署项目。1)Linux的介绍,Linux的安装:VMwareW…

    2022年4月13日
    48
  • 玩转ADB命令(ADB命令使用大全)

    玩转ADB命令(ADB命令使用大全)我相信做Android开发的朋友都用过ADB命令,但是也只是限于安装应用push文件和设备重启相关,根深的也不知道了,其实我们完全可以了解多一点,有一些不常用的场景我们至少应该知道它可以做到,比如,我们知道adbinstall却不知道adbshellamstart。前者是用来安装软件,后者用来打开软件,后者的一个使用场景让我对他重视:公司定制Android系统,在调试屏幕的时候要看是否满屏

    2022年5月13日
    33
  • 用心做软件—细节决定成败「建议收藏」

    用心做软件—细节决定成败「建议收藏」软件是什么?也许在编程者的眼中这是自己智慧的结晶,是技术运用的成果。但是在用户的眼中呢,用户会在乎你到底用了多少高级的技术、用了什么前卫的技术吗?我想大部分用户是不会管的,无论你是C#做的,Java做的,C++还是C做的,你的系统是Windows还是Linux,android还是塞班。用户的眼中你的软件只是一件产品,那么既然是产品,就要有价值,要能为用户带来方便,能为用户解决问题。当今的互联网上,

    2022年9月23日
    0
  • 采用大杀招QEMU调试Linux内核代码

    采用大杀招QEMU调试Linux内核代码

    2022年1月17日
    42
  • linux与g++基本知识「建议收藏」

    linux与g++基本知识「建议收藏」基本知识gcc、g++、gdb区别yum、apt、rpm区别二进制包和源码包linux动态库和静态库cpp文件编译流程g++ 重要参数生成库文件生成静态库生成动态库GDB调试gcc、g++、gdb区别GCC:GNU Compiler Collection(GUN 编译器集合),它可以编译C、C++、JAV、Fortran、Pascal、Object-C、Ada等语言。gcc是GCC中的GUN C Compiler(C 编译器)g++是GCC中的GUN C++ Compiler(C++编译器)gd

    2022年8月9日
    2
  • 自动化测试 数据驱动(自动化测试解决数据错误)

    数据驱动将测试数据和测试行为完全分离,实施数据驱动测试步骤如下:A、编写测试脚本,脚本需要支持从程序对象、文件或者数据库读入测试数据;B、将测试脚本使用的测试数据存入程序对象、文件或者数据库等外部介质中;C、运行脚本过程中,循环调用存储在外部介质中的测试数据;D、验证所有的测试结果是否符合预期结果; 1、使用unittest和ddt进行数据驱动:#-*-coding…

    2022年4月18日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号