# HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest

xiaoxiao2021-02-28  10

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

import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args){ BigDecimal a, b, tmp, gold; BigDecimal l, r, eps, mid; l = BigDecimal.valueOf(2.236067); r = BigDecimal.valueOf(2.236068); mid = BigDecimal.valueOf(2.236067); eps = BigDecimal.valueOf(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001); while(r.subtract(l).compareTo(eps) > 0){ mid = l.add(r).divide(BigDecimal.valueOf(2)); if(BigDecimal.valueOf(5).subtract(mid.multiply(mid)).compareTo(eps)<0) r = mid; else l = mid; } gold = mid.add(BigDecimal.ONE).divide(BigDecimal.valueOf(2)); Scanner in = new Scanner(System.in); while(in.hasNextBigDecimal()){ a = in.nextBigDecimal(); b = in.nextBigDecimal(); if(a.compareTo(b)>0){ tmp = a; a = b; b = tmp; } BigDecimal c = b.subtract(a).multiply(gold); if(c.setScale(0,BigDecimal.ROUND_DOWN).equals(a)==true) System.out.println("0"); else System.out.println("1"); } } }