题目链接:

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. Design Tip #142 Building Bridges

    http://www.kimballgroup.com/2012/02/design-tip-142-building-bridges/ The dominant topologies of Data ...

  2. javaScript事件(三)事件对象

    一.事件 二.事件流 以上内容见:javaScript事件(一)事件流 三.事件处理程序 四.IE事件处理程序 以上内容见javaScript事件(二)事件处理程序 五.事件对象 1.认识事件对象 事 ...

  3. docker containerd shim分析

    // containerd-shim is a small shim that sits in front of a runtime implementation that allows it to ...

  4. 《TCP/IP详解 卷一》读书笔记-----动态路由协议

    1.以下条件只要有一个不满足,则需要使用动态路由协议:1)网络规模小,2)只有一个连接点用于连接其他网络,3)没有冗余的路由器(一般用作备份) 2.所谓动态路由就是各个路由器与自己相邻的路由器交换各自 ...

  5. codeforces 480A A. Exams(贪心)

    题目链接: A. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. ckplayer播放器去掉右边的开关灯分享插件

    在上一篇文章中介绍了如何使用ckplayer播放器,但是有的人不需要CK播放器右边的开关灯分享插件,那么就需要把该插件给去掉,方法也很简单. 第一步:先打开ckplayer.js里找到下面三行删除掉 ...

  7. HDU 5057 Argestes and Sequence --树状数组(卡内存)

    题意:给n个数字,每次两种操作: 1.修改第x个数字为y. 2.查询[L,R]区间内第D位为P的数有多少个. 解法:这题当时被卡内存了,后来看了下别人代码发现可以用unsigned short神奇卡过 ...

  8. Unity键值(KeyCode)

    Unity的Input管理 keyCode示例 keyCode Demo function OnGUI(){ var e:Event=Event.current; if(e.isKey){ Debug ...

  9. 026医疗项目-模块二:药品目录的导入导出-导入功能的Service的编写

    这个导入功能要实现的效果是: 思路是: 因为我们最后是在Action层中调用的HxlsRead工具,这个工具传入的就是我们要实现的上一篇文章说到的实现了HxlsOptRowsInterface接口的类 ...

  10. [py]导入模块3种方法

        import os <--通过os.system()引用 from os import * <---直接system()引用,不建议使用 from os import argv i ...