HDU 5973-Game of Taking Stones(威佐夫博弈-JAVA BigDecimal)
来源:互联网 发布:java开发windows软件 编辑:程序博客网 时间:2024/06/04 17:44
Game of Taking Stones
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 459 Accepted Submission(s): 176
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 18 44 7
Sample Output
010
Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
威佐夫博弈的裸题,就是咳咳咳…数据量巨大,JAVA BigDecimal 可搞。
要精确到小数点后100位,精度要求太高了∑(っ °Д °;)っ
这个黄金分割数×(b-a)后如果等于a,那么为0,否则为1。(默认a<b)
import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner;public class Main{ public static BigDecimal setScaleRoundDown(int newScale, BigDecimal b) { return b.setScale(newScale, BigDecimal.ROUND_DOWN); } public static void main(String[] args) { Scanner cin=new Scanner(System.in); BigDecimal a,b,tmp,yi,er,x,tp,l; while(cin.hasNextBigDecimal()) { a=cin.nextBigDecimal(); b=cin.nextBigDecimal(); l= new BigDecimal(String.valueOf("0")); if(a.compareTo(l)==0) { if(b.compareTo(l)==0) { System.out.println("0"); continue; } } if(a.compareTo(b)==0) { System.out.println("1"); continue; } if(a.compareTo(b)>0) { tp=a; a=b; b=tp; } x=b.subtract(a); tmp = new BigDecimal(String.valueOf("1.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807")); tmp=tmp.multiply(x); //System.out.println(tmp); //tmp.setScale(0,BigDecimal.ROUND_DOWN); //System.out.println(setScaleRoundDown(0, tmp)); if(setScaleRoundDown(0, tmp).compareTo((a))==0) System.out.println("0"); else { System.out.println("1"); } } }}
0 0
- HDU 5973-Game of Taking Stones(威佐夫博弈-JAVA BigDecimal)
- HDU-5973-Game of Taking Stones(JAVA-BigDecimal+Wythoff博弈)
- HDU 5973 Game of Taking Stones 博弈+高精度
- Game of Taking Stones (大数 + 威佐夫博弈 java写的)
- HDU 5973Game of Taking Stones 51nod 1185 威佐夫游戏 V2(威佐夫博弈)
- HDU-5973 Game of Taking Stones(威佐夫博弈+高精度)(C++高精度)
- HDU5973 Game of Taking Stones (大数博弈)
- [hdu 5973 Game of Taking Stones] Wythoff Game+大数运算
- Game of Taking Stones (hdu5973)——2016大连现场赛C题 威佐夫博弈
- HDU 5973 ICPC 大连 Game of Taking Stones
- HDU-5973 Game of Taking Stones(大数+二分求精度)
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- HDOJ 5973 Game of Taking Stones
- 2016 ICPC 大连 C Game of Taking Stones 【威佐夫博弈+大数+高精度】
- Game of Taking Stones(威佐夫博奕 待整理)
- codeforces 768 E Game of Stones(博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- 循序渐进学HotFix (基于Gradle 1.5+版本)
- 剑指offer-面试题54-表示数值的字符串
- 12.剑指offer-平衡二叉树的判定
- Mybatis基础
- Uncaught TypeError: Cannot read property 'msie' of undefined
- HDU 5973-Game of Taking Stones(威佐夫博弈-JAVA BigDecimal)
- 常见总结
- python脚本处理代码注释规范化
- MeanShift聚类算法
- java常见问题
- Elasticsearch(四)-映射和分析
- 两列样本的差异基因筛选
- Hibernate学习笔记之四
- Java内存泄露原因详解