Game of Taking Stones

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 456    Accepted Submission(s): 174

Problem Description
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
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.
 
Output
For 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
 
Source
 
Recommend
 
 
裸bash game,大数
唯一要注意的就是开方要精确到小数点后100位
JAVA大数,
 import java.math.*;
import java.util.Scanner; public class Main {//类名要用Main
public static void main(String[] args){ //BigDecimal gr = new BigDecimal(((Math.sqrt(5.0)) + 1) / 2);
BigDecimal gr = new BigDecimal("1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137");
//System.out.println("gr = " + gr);
BigDecimal a2, b2;
BigInteger a, b, t;
BigDecimal k;
BigInteger k2;
Scanner sc=new Scanner(System.in);
while (sc.hasNextBigInteger()) {
a=sc.nextBigInteger();
b=sc.nextBigInteger();
if (a.compareTo(b) > ) {
t = a;
a = b;
b = t;
}
a2 = new BigDecimal(a);
b2 = new BigDecimal(b); k = (b2.subtract(a2));
k = k.multiply(gr);
k2 = k.toBigInteger(); if (k2.compareTo(a) == ) {
System.out.println("");
} else {
System.out.println("");
}
} }
}

JAVA大数类的使用还不是很熟练。

 
 

hdu 5973 Game of Taking Stones(大数,bash game¥)的更多相关文章

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

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

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

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

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

  4. HDU 5973 Aninteresting game 威佐夫博奕(Wythoff Game)

    HDU 5973:http://acm.hdu.edu.cn/showproblem.php?pid=5975 题意: 有两堆石子,每次可以从一堆石子中取任意个,或者从两堆石子中取相同个数的石子.两个 ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1250 Hat's Fibonacci(大数相加)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...

  7. HDOJ/HDU 1297 Children’s Queue(推导~大数)

    Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...

  8. HDU 1023 Train Problem II (大数卡特兰数)

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1226 bfs+余数判重+大数取余

    题目: 超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. Java 语言基础(一)

    大多数编程语言都包括以下基本内容: 关键字 标识符 注释 常量和变量 运算符 语句 函数 数组 学习语言最重要的两点: 该语言基础的表现形式是什么 这些东西什么时候使用 关键字 在程序语言中有特殊含义 ...

  2. "零代码”开发B/S企业管理软件之一 :怎么创建数据库表

    声明:该软件为本人原创作品,多年来一直在使用该软件做项目,软件本身也一直在改善,在增加新的功能.但一个人总是会有很多考虑不周全的地方,希望能找到做同类软件的同行一起探讨. 本人文笔不行,能把意思表达清 ...

  3. 转!!SQL左右连接中的on and和on where的区别

    原博文地址:http://blog.csdn.net/xingzhemoluo/article/details/39677891 原先一直对SQL左右连接中的on and和on where的区别不是太 ...

  4. php smarty模板引擎

    <?php /* 一.什么是smarty? smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲, 目的就是要使用PHP程序员同美工分离,使用的程序员改 ...

  5. form表单学习

    1.http://www.cnblogs.com/fish-li/archive/2011/07/17/2108884.html 2.http://www.cnblogs.com/polk6/arch ...

  6. 解决 hybird 应用中重复获取 WebView,导致页面元素无法识别的问题

    转载地址:http://blog.csdn.net/testman930/article/details/50799532 问题描述 在测APP的业务流,WebView和Native模式耦合在一起.例 ...

  7. LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: --异常记录

    升级了JDK之后,启动应用,直接抛出此异常.网上搜罗半天,没有正确的解决方案. 然后想到了是“升级了JDK”,重新检查所有JDK相关的配置的地方,在Debug Configurations里找到启动时 ...

  8. Java集合(7):HashMap

    一.HashMap介绍 HashMap是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据hash算法来来计算 ...

  9. 格式化字符串--format用法

    print("hello {leon}".format(leon="world!")) #format 是一个格式化字符穿的方法. print("he ...

  10. nginx ip无法访问

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭firewall: systemctl stop firewalld.service #停止f ...