Two people face two piles of stones and make a game. They take turns to take stones. As game rules, there are two different methods of taking stones: One scheme is that you can take any number of stones in any one pile while the alternative is to take the same amount of stones at the same time in two piles. In the end, the first person taking all the stones is winner.Now,giving the initial number of two stones, can you win this game if you are the first to take stones and both sides have taken the best strategy?

InputInput contains multiple sets of test data.Each test data occupies one line,containing two non-negative integers a andb,representing the number of two stones.a and b are not more than 10^100.OutputFor each test data,output answer on one line.1 means you are the winner,otherwise output 0.Sample Input

2 1
8 4
4 7

Sample Output

0
1
0
题解:威佐夫博弈板题,使用java大数;
对于一个奇异状态满足,a[k]=k*(sqrt(5)+1)/2;b[k]=a[k]+k;
参考代码:
 import java.math.BigDecimal;
import java.util.Scanner; public class Main{
public static void main(String[] args){
BigDecimal two=new BigDecimal(2);
BigDecimal three=new BigDecimal(3);
BigDecimal five=new BigDecimal(5);
BigDecimal l=two, r=three;
for(int i=0; i<500; i++){
BigDecimal mid=l.add(r).divide(two);
if(mid.multiply(mid).compareTo(five)<0) l=mid;
else r=mid;
}
BigDecimal gold=l.add(BigDecimal.ONE).divide(two);
BigDecimal a, b;
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
a=cin.nextBigDecimal();
b=cin.nextBigDecimal();
if(a.compareTo(b)>0){
BigDecimal tmp=a;
a=b;b=tmp;
}
a=a.setScale(0, BigDecimal.ROUND_DOWN);
b=b.subtract(a).multiply(gold);
b=b.setScale(0, BigDecimal.ROUND_DOWN);
if(a.compareTo(b)==0) System.out.println("0");
else System.out.println("1");
}
}
}

HDU5973 Game of Geting Stone(威佐夫博弈)的更多相关文章

  1. 【hdu5973】高精度威佐夫博弈

    题意:输入a, b表示两堆石头数目,威佐夫博弈,问:先手胜负? a, b <= 1e100. 高精度.当a > b时, a = (a-b)*黄金分割比 时是先手败状态.因为a, b < ...

  2. nim3取石子游戏 (威佐夫博弈)

    http://www.cnblogs.com/jackge/archive/2013/04/22/3034968.html 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有 ...

  3. HDU 5973 Game of Taking Stones 威佐夫博弈+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5973 Game of Taking Stones Time Limit: 2000/1000 MS ...

  4. HD 2177(威佐夫博弈 入门)

    取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. HDU2177:取(2堆)石子游戏(威佐夫博弈)

    Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同 ...

  6. 【POJ1067】取石子游戏 (威佐夫博弈)

    [题目] Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的 ...

  7. HDU 2177 取(2堆)石子游戏 (威佐夫博弈)

    题目思路:威佐夫博弈: 当当前局面[a,b]为奇异局时直接输出0 否则: 1.若a==b,输出(0 0): 2.将a,b不停减一,看能否得到奇异局,若有则输出: 3.由于 ak=q*k(q为黄金分割数 ...

  8. POJ 1067 取石子游戏 威佐夫博弈

    威佐夫博弈(Wythoff Game):有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 我们用(ak,bk)(ak ≤ bk ,k= ...

  9. HDU 1527 取石子游戏(威佐夫博弈)

    基础威佐夫博弈,判断奇异局势即可,判断方式为k为两数之差绝对值,(sqrt(5) + 1) / 2 * k若等于两数小者则为奇异局势,也就是必败态. #include<stdio.h> # ...

随机推荐

  1. 可保图片不变形的object-fit

    Object-fit 我们有时候浏览一些网站的时候,偶尔会遇到这种情况:  明显它喵的形变了,尤其是这种这么业余的失误,还是出现在一个专门做图片的网站上. 产生这种现象的原因是:图片写了固定的宽高,这 ...

  2. google在nature上发表的关于量子计算机的论文(Quantum supremacy using a programmable superconducting processor 译)— 附论文

    Google 2019年10月23号发表在Nature(<自然><科学>及<细胞>杂志都是国际顶级期刊,貌似在上面发文两篇,就可以评院士了)上,关于量子计算(基于 ...

  3. 关于jQuery easyUI 添加合计统计行

    首先在onLoadSuccess中添加计算函数:计算方法按各自业务需要,我做了一个判断非数 然后再在gatagrid表格添加行,$('#div').datagrid('appendRow', {... ...

  4. WebSocket插件

    ;!(function(window){ "use strict"; let Event = { wsMesEvent:function(message){ console.log ...

  5. hdu 1907 John (尼姆博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  6. opencv随笔1

    图像处理技术一般包括图像压缩,增强和复原,匹配 描述和l识别 3 个部分. 图像处理一般指数字图像处理 ( Digitallmage Processing). 其中,数字图像是指用工业相机.摄像机.扫 ...

  7. jdbc-mysql测试例子和源码详解

    目录 简介 什么是JDBC 几个重要的类 使用中的注意事项 使用例子 需求 工程环境 主要步骤 创建表 创建项目 引入依赖 编写jdbc.prperties 获得Connection对象 使用Conn ...

  8. Matplotlib入门简介

    Matplotlib是一个用Python实现的绘图库.现在很多机器学习,深度学习教学资料中都用它来绘制函数图形.在学习算法过程中,Matplotlib是一个非常趁手的工具. 一般概念 图形(figur ...

  9. Jenkins 实现前端自动打包,自动部署代码及邮件提醒功能

    在之前的公司,我们前端使用webpack构建项目,项目构建完成后,我们会使用ftp或linux的一些命令工具上传我们的文件到服务器上,这种方式虽然是可以,但是最近面试的时候,人家会问我前端如何部署项目 ...

  10. 【如何让代码变“高级”(一)】-Spring组合注解提升代码维度

    原创不易,点个赞