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. 我的Android进阶之旅------>Android Studio 快捷键整理分享

    正式转战Android Studio了,首先把Android Studio的快捷键摘录下来,以备后用. (官网的快捷键列表如下  https://developer.android.com/studi ...

  2. Django组件 - cookie、session、用户认证组件

    一.cookie 1.会话跟踪技术 1)什么是会话跟踪技术 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话 ...

  3. JS获取当年当月最后一天日期

    <html xmlns="http://www.w3.org/1999/xhtml" > <meta charset="UTF-8"> ...

  4. 简明python教程四-----模块

    模块基本是一个包含了所有你定义的函数和变量的文件.为了在其他程序中重用模块,模块的文件名必须以.py为扩展名. #!/usr/bin/python #Filename:using_sys.py imp ...

  5. Angular 学习笔记 :初识 $digest , $watch , $apply,浅析用法 。

    传统的浏览器事件循环 :浏览器本身一直在等待事件,并作出响应.如果你点击一个button或者在input 中输入字符,我们在 JS 中 监听这些事件并设定了回调函数,那么这些事件被触发以后,回调函数就 ...

  6. (转)CTO的烦恼:为啥差距就这么大呢?

    话说胖哒是一只CTO,近来遇到了一些小烦恼… 胖哒表示这么多问题想想就头大啊! 一直听说用Docker解决问题不错,于是两个月前,胖哒不远万里来到DockerCon 16,打算向国外的Docker先行 ...

  7. 转:Oracle中的日期和字符串互相转换

    TO_DATE格式(以时间:2007-11-02   13:45:25为例)          Year:             yy two digits 两位年                显 ...

  8. 113. Path Sum II(求等于某个数的所有路径)

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  9. Python 中全局变量的实现

    一.概述 Python 中全局变量的使用场景不多,但偶尔也有用武之处. 如在函数中的初始化,有时需要从外部传入一个全局变量加以控制.或者在函数中,使用连接池时,也可能有使用全局变量的需要. 广义上的全 ...

  10. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...