思路:有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。

游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。

最后把石子全部取完者为胜者。

现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。

a,b<=1e100

思路:裸的威佐夫博弈,网上找了一个Java的高精度板子

主要是把黄金分割点用二分精确到小数点后100位

 import java.math.BigDecimal;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
BigDecimal two=BigDecimal.valueOf(2);
BigDecimal five=BigDecimal.valueOf(5);
BigDecimal eps= new BigDecimal("-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");
BigDecimal l=new BigDecimal("2.2360679774997");
BigDecimal r=new BigDecimal("2.2360679774998");
BigDecimal m=null;
while(l.subtract(r).compareTo(eps)<0)
{
m=l.add(r).divide(two);
if(m.multiply(m).subtract(five).abs().compareTo(eps.abs())<0) break;
if(m.multiply(m).subtract(five).compareTo(eps)<0) l=m;
else r=m;
}
BigDecimal Gold=m.add(BigDecimal.ONE).divide(two);
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
BigDecimal a=sc.nextBigDecimal(),b=sc.nextBigDecimal();
if(a.compareTo(b)>0)
{
BigDecimal t=a;
a=b;
b=t;
}
BigDecimal c=b.subtract(a).setScale(0,BigDecimal.ROUND_FLOOR).multiply(Gold);
c=c.setScale(0,BigDecimal.ROUND_FLOOR);
if(a.equals(c)) System.out.println("0");
else System.out.println("1");
}
}
}

【HDOJ5973】Game of Taking Stones(Java,威佐夫博弈)的更多相关文章

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

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

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

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

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

  4. HDU5973 Game of Geting Stone(威佐夫博弈)

    Two people face two piles of stones and make a game. They take turns to take stones. As game rules, ...

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

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

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

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

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

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

  8. hdu1527取石子游戏(威佐夫博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=2177 取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    M ...

随机推荐

  1. TCP/IP与OSI参考模型原理

    网络是很重要同时也是很难理解的知识,这篇文章将会用自己容易理解的方式来记录有关网络的tcp与osi模型内容,不求专业深刻,但求通俗易懂也好. OSI参考模型 OSI定义了网络互连的七层框架(物理层.数 ...

  2. Date.prototype.Format---对Date的扩展

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  3. wampserver怎么设置外网可访问

    wampserver配置httpd.conf允许外网访问? 在电脑上开启wamp服务后,默认是禁止外部网络访问的,如果您想要同一局域网中的设备能够访问PC上的web项目,则需要对httpd.conf文 ...

  4. 2019年Vue学习路线图

    https://juejin.im/entry/5c108864f265da61726555ed 官网: https://cn.vuejs.org/index.html js引入地址 https:// ...

  5. C++构造函数实例——拷贝构造,赋值

    #define _CRT_SECURE_NO_WARNINGS //windows系统 #include <iostream> #include <cstdlib> #incl ...

  6. 记忆化搜索:POJ1579-Function Run Fun(最基础的记忆化搜索)

    Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14815 Accepted: 7659 Des ...

  7. 笔记-python-standard library-17.1 threading

    笔记-python-standard library-17.1 threading 1.      threading source code: Lib/threading.py 本模块构建高级别的线 ...

  8. 信号量和互斥量C语言示例理解线程同步

    Table of Contents 1. 线程同步 1.1. 用信号量进行同步 1.2. 用互斥量进行同步 2. 参考资料 线程同步 了解线程信号量的基础知识,对深入理解python的线程会大有帮助. ...

  9. UVa 1455 Kingdom 线段树 并查集

    题意: 平面上有\(n\)个点,有一种操作和一种查询: \(road \, A \, B\):在\(a\),\(b\)两点之间加一条边 \(line C\):询问直线\(y=C\)经过的连通分量的个数 ...

  10. leetcode 【 Container With Most Water 】python 实现

    题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...