题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5973

Game of Taking Stones

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#### 问题描述
> 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?

输入

Input 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.

输出

For each test data,output answer on one line.1 means you are the winner,otherwise output 0.

样例输入

2 1

8 4

4 7

样例输出

0

1

0

题解

威佐夫博弈+大数

对于a,b(a<b),如果有floor((b-a)*((sqrt(5)+1)/2))==a,则为必败态。

import java.awt.peer.SystemTrayPeer;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner; public class Main {
public static void main(String[] args) { BigDecimal two=new BigDecimal(2);
BigDecimal thr=new BigDecimal(3);
BigDecimal fiv=new BigDecimal(5); BigDecimal l=two,r=thr; for(int i=0;i<500;i++){
BigDecimal mid=r.add(l).divide(two);
if(mid.multiply(mid).compareTo(fiv)<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;
} BigDecimal zero=a.subtract(b.subtract(a).multiply(gold).setScale(0,BigDecimal.ROUND_FLOOR)); //100位
BigDecimal sma=new BigDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); if(zero.abs().compareTo(sma)<0){
System.out.println("0");
}else{
System.out.println("1");
} } }
}

HDU 5973 Game of Taking Stones 威佐夫博弈+大数的更多相关文章

  1. HDU 5973 Game of Taking Stones (威佐夫博弈+高精度)

    题意:给定两堆石子,每个人可以从任意一堆拿任意个,也可以从两堆中拿相同的数量,问谁赢. 析:直接运用威佐夫博弈,floor(abs(a, b) * (sqrt(5)+1)/2) == min(a, b ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是 ...

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

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

  4. 题解报告:hdu 1527 取石子游戏(威佐夫博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石 ...

  5. HDU - 5973 Game of Taking Stones (威佐夫博弈 高精度)

    题目描述: Two people face two piles of stones and make a game. They take turns to take stones. As game r ...

  6. hdu 1527 (威佐夫博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石 ...

  7. 取石子游戏 HDU 1527 博弈论 威佐夫博弈

    取石子游戏 HDU 1527 博弈论 威佐夫博弈 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两 ...

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

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

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

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. VMware Workstation不可恢复的错误:(vmui)

    虚拟机中部署项目,由于项目的日志是gbk的,就把虚拟机中linux编码改成gbk了,结果问题来了,日志显示中文正常了,但是虚拟机运行一下就出错了,注意虚拟机出错,并没导致linux也挂掉,只是linu ...

  2. [转]Worksheet.Change Event (Excel)

    本文转自:https://msdn.microsoft.com/en-us/library/office/ff839775.aspx#AboutContributor Example   The fo ...

  3. web前端的渐进增强式开发模型

    渐进增强是前端开发的根本基础.从根本的层面上讲,它可以将HTML,CSS,JavaScript这三者的功能分离开来,这能让当前的项目开一个好头.我们在创建项目的开始要将这三者分开,它们对应的称呼是结构 ...

  4. Python中的逗号有什么作用?

    最近研究python  遇到个逗号的问题 一直没弄明白 今天总算搞清楚了 1.逗号在参数传递中的使用: 这种情况不多说  没有什么不解的地方 就是形参或者实参传递的时候参数之间的逗号 例如def  a ...

  5. 用运算符代替if、else

  6. Wordpress 3.5.1的debug流水账

    一个合作网站是基于Wordpress做的, 不能正常使用FeedWordPress这个插件, 对方没有开发者, 只有一个类似于美工和编辑的人, 因为我在本地使用同样的版本(Wordpress 3.5. ...

  7. 八、Foundation -常用结构体

    一.NSRange 在foundation/NSRange.h中对NSRange的定义 typedef struct _NSRange{ NSUInteger location; NSUInteger ...

  8. gridpanel分组汇总

    [ExtJS5学习笔记]第三十节 sencha extjs 5表格gridpanel分组汇总 2015-05-31     86 本文地址:http://blog.csdn.net/sushengmi ...

  9. 025医疗项目-模块二:药品目录的导入导出-HSSF导入类的封装

    上一篇文章提过,HSSF的用户模式会导致读取海量数据时很慢,所以我们采用的是事件驱动模式.这个模式类似于xml的sax解析.需要实现一个接口,HSSFListener接口. 原理:根据excel底层存 ...

  10. C++ STL之vector详解

    转自http://blog.sina.com.cn/s/blog_9f1c0931010180cy.html Vectors   vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作 ...