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大数,
  1. import java.math.*;
  2. import java.util.Scanner;
  3.  
  4. public class Main {//类名要用Main
  5. public static void main(String[] args){
  6.  
  7. //BigDecimal gr = new BigDecimal(((Math.sqrt(5.0)) + 1) / 2);
  8. BigDecimal gr = new BigDecimal("1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137");
  9. //System.out.println("gr = " + gr);
  10. BigDecimal a2, b2;
  11. BigInteger a, b, t;
  12. BigDecimal k;
  13. BigInteger k2;
  14. Scanner sc=new Scanner(System.in);
  15. while (sc.hasNextBigInteger()) {
  16. a=sc.nextBigInteger();
  17. b=sc.nextBigInteger();
  18. if (a.compareTo(b) > ) {
  19. t = a;
  20. a = b;
  21. b = t;
  22. }
  23. a2 = new BigDecimal(a);
  24. b2 = new BigDecimal(b);
  25.  
  26. k = (b2.subtract(a2));
  27. k = k.multiply(gr);
  28. k2 = k.toBigInteger();
  29.  
  30. if (k2.compareTo(a) == ) {
  31. System.out.println("");
  32. } else {
  33. System.out.println("");
  34. }
  35. }
  36.  
  37. }
  38. }

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主页导航:fragment+viewpager

    简单实现Fragment+ViewPager实现主页导航控制,效果如下: 一.activity_main.xml布局文件: <?xml version="1.0" encod ...

  2. Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)

    [正文] 一.HTTP协议初探: HTTP(Hypertext Transfer Protocol)中文 "超文本传输协议",是一种为分布式,合作式,多媒体信息系统服务,面向应用层 ...

  3. JSP使用网站访问人数统计功能,方法与技巧

    实现网站访问人数统计功能的步骤: 创建静态登录页面,并指定表单提交由登录处理页面进行处理. 创建登录处理页面获得登录信息,查询数据库,判断该用户是否注册,如果该用户已注册,把已登录用户的信息保存在一个 ...

  4. java反射基础知识(五)反射应用实践

    详解Java反射各种应用   Java除了给我们提供在编译期得到类的各种信息之外,还通过反射让我们可以在运行期间得到类的各种信息.通过反射获取类的信息,得到类的信息之后,就可以获取以下相关内容: Cl ...

  5. 在w3cschool学完html,css,javascript,jquery以后,还是不会做前端怎么办?

    w3cschool是一个非盈利性的在线技术学习网站,提供按W3C标准编写的基础教程.完整的看完w3cschool上面的手册,可以基本掌握编程语法.基础性的东西通常都会比较零散,因此,在学习一段时间后, ...

  6. 解决XAMPP不能启动Apche服务问题

    打开command prompt输入命令 netstat -ano 查看哪个 PID的进程占用了80端口.结果是inetinfo.exe 网上查了下,正是WIN XP IIS的进程,但是又不想删,就只 ...

  7. CodeMatic动软自动生成Nhibernate

    前两天调查了下自动生成工具MyGeneration和codesmith前一个版本已经不更新了后面一个太高级生成 的代码包含了太多东西,没整明白.不过生成的xmlmapping很强大.所以干脆整合一下c ...

  8. redis 笔记03 RDB 持久化、AOF持久化、事件、客户端

    RDB 持久化 1. RDB文件用于保存和还原Redis服务器所有数据库中的所有键值对数据. 2. SAVE命令由服务器进程直接执行保存操作,所以该命令会阻塞服务器. 3. BGSAVE由子进程执行保 ...

  9. 图像运动去模糊(Motion Deblurring)代码

    http://blog.csdn.net/qianliheshan/article/details/12853157 http://www.di.ens.fr/~whyte/ Efficient De ...

  10. .NET计时器的使用-Stopwatch类

    作用: 微软提供的常用于统计时间消耗的类,作为一个固定的API接口供大家使用. 先看代码: using System; using System.Collections.Generic; using ...