hdu 5973 Game of Taking Stones(大数,bash game¥)

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) > 0) {
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) == 0) {
31                 System.out.println("0");
32             } else {
33                 System.out.println("1");
34             }
35         }
36         
37     }
38 }

JAVA大数类的使用还不是很熟练。

 
 
原文地址:https://www.cnblogs.com/gongpixin/p/6794495.html