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. python的进程与线程

    一.进程与线程的相关概念 1.什么是进程 进程是一个程序在一个数据集上的一次动态执行过程. 进程一般由程序,数据集,进程控制块三部分组成. 2.什么是线程 线程也叫轻量级进程,它是一个基本的CPU执行 ...

  2. Java 集合框架工具类

    Collections Arrays Collections 集合框架的工具类, 里面的方法都是静态的, 可以直接使用类名调用 常用方法 1. sort(List<T> list); // ...

  3. Django HttpResponse对象详解

    HttpResponse对象 Django服务器接收到客户端发送过来的请求后,会将提交上来的这些数据封装成一个HttpRequest对象传给视图函数.那么视图函数在处理完相关的逻辑后,也需要返回一个响 ...

  4. IOS研究之IOS7四种后台机制

     IOS 7中,实际上APP拥有四种后台模式.不管是哪一种后台机制,均须要利用苹果给予的对应后台接口实现.IOS7系统中,开发人员能够灵活利用多种后台接口(API)实现更加智能的应用操作. 对获取 ...

  5. 使用 10046 查看执行计划并读懂 trace 文件

    查看 sql 执行计划的方法有许多种, 10046 事件就是其中的一种. 与其他查看 sql 执行计划不同, 当我们遇到比较复杂的 sql 语句, 我们可以通过 10046 跟踪 sql 得到执行计划 ...

  6. [转]Asp.net MVC 中Ajax的使用

    Asp.net MVC 抛弃了Asp.net WebForm那种高度封装的控件,让我们跟底层的HTML有了更多的亲近.可以更自由.更灵活的去控制HTML的结构.样式和行为.而这点对于Ajax的应有来说 ...

  7. js 数组判断是否包含某元素 或 数组去重

    判断包含: 1.借助 jquery  $.inArray(obj.UNIVERSITY_NAME, arryDatas) < 0var arr = [ "xml", &quo ...

  8. python约束 与MD5加密写法

    python 中约束写法有两种 1 常用的通过继承关系主动抛出异常  2 通过抽象类+抽象方法 1 常用的通过继承关系主动抛出异常写法 在本send方法中报错不会抛出异常, class BaseMes ...

  9. 解决Can't connect to local MySQL server through socket '/tmp/mysql.sock'

    0 Problem 电脑重启后用python的MySQLdb连接数据库报错 Can't connect to local MySQL server through socket '/tmp/mysql ...

  10. 关于获得MFC窗口其它类指针的方法(csdn)

    转自:http://tieba.baidu.com/p/252804018 访问应用程序的其它类 获得CWinApp: -在CMainFrame,CChildFrame,CDocument,CView ...