hdu -- 5973

本题就是纯的威佐夫博弈 题型,但是由于数据太多,到10的100次方,所以要将 k 的小数点后面的数取到100位(k 的定义就是黄金分割数的倒数,详细定义请看如下链接 https://baike.so.com/doc/25603430-26651954.html)
黄金分割术的小数点后面一百位请看如下链接
http://blog.csdn.net/qq_38295645/article/details/78929900
代码如下:

package 大数相加;

import java.math.*;
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
         BigDecimal gr = new BigDecimal("1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137");
         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) > 0)
             {
                 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) == 0) 
                 System.out.println("0");
             else 
                 System.out.println("1");
        }

    }
 }

你可能感兴趣的:(hdu -- 5973)