HDU 5973 威佐夫博弈+JAVA高精度
来源:互联网 发布:scratch趣味编程 ppt 编辑:程序博客网 时间:2024/06/10 04:02
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?
2 18 44 7
010
import java.util.*;import java.math.*;public class Main {public static void main(String[] args) {Scanner scan=new Scanner(System.in);BigDecimal TWO=new BigDecimal("2");BigDecimal FIVE=new BigDecimal("5");BigDecimal EPS=new BigDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");BigDecimal l=new BigDecimal("0");BigDecimal r=new BigDecimal("5");BigDecimal m=new BigDecimal("2.5");BigDecimal ONE= new BigDecimal("1");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; } //System.out.println(r);r=r.add(ONE).divide(TWO);while(scan.hasNext()){String str1=scan.next();String str2=scan.next();BigDecimal x=new BigDecimal(str1);BigDecimal y=new BigDecimal(str2);if(x.compareTo(y)>0){TWO=x;x=y;y=TWO;}BigDecimal z=y.subtract(x);BigDecimal w=r.multiply(z);w=w.setScale(0, BigDecimal.ROUND_DOWN);if(w.equals(x))System.out.println(0);elseSystem.out.println(1);}}}
阅读全文
0 0
- HDU 5973 威佐夫博弈+JAVA高精度
- HDU-5973 Game of Taking Stones(威佐夫博弈+高精度)(C++高精度)
- HDU 5973 Game of Taking Stones 博弈+高精度
- 威佐夫博弈(高精度)
- hdu 5973 大数威佐夫博弈
- HDU-5973 威佐夫博弈+大数
- hdu 1063 java 高精度
- HDU-4762 Java高精度
- HDU 5754 博弈(威佐夫博弈)
- hdu 1063 Exponentiation(java+高精度)
- HDU 5241 - Friends <高精度 + Java>
- hdu 5050 java高精度GCD
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- HDU 5973 博弈
- 威佐夫博弈 hdu 2177
- hdu 1527威佐夫博弈
- HDU 2177 威佐夫博弈
- hdu 2177 威佐夫博弈
- Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
- Android【官方教程】NDK 概念
- angular的一些基本常识
- mySc day8
- 概率编程——未来也可以这样预测
- HDU 5973 威佐夫博弈+JAVA高精度
- cron表达式
- 简单的算法问题4——移除数组中重复的元素
- 记一次惊险的文件恢复经历Eclipse saved my day
- 输入框input值变化
- 【13.2】c++ primer plus 课后编程答案
- Codeforces
- mySc day10
- FastDFS分布式文件系统在Linux上的部署和安装