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大数,
 import java.math.*;
import java.util.Scanner; public class Main {//类名要用Main
public static void main(String[] args){ //BigDecimal gr = new BigDecimal(((Math.sqrt(5.0)) + 1) / 2);
BigDecimal gr = new BigDecimal("1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137");
//System.out.println("gr = " + gr);
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) > ) {
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) == ) {
System.out.println("");
} else {
System.out.println("");
}
} }
}

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

 
 

最新文章

  1. imagepool前端图片加载管理器(JavaScript图片连接池)
  2. 阿里云的9折推荐码 8DIER4
  3. FIR.im Weekly - 这是多产的一周
  4. hbase伪分布式安装(转)
  5. loadrunner处理HTTP重定向请求
  6. BootstrapValidator验证表单用法
  7. 【问题&解决】解决 Android SDK下载和更新失败“Connection to https://dl-ssl.google.com refused”的问题
  8. 像jQuery那样,采用链式方法,封装一个方法:CSS()
  9. js求和算法研究
  10. Neo4j简介
  11. 冒泡排序 JAVA版
  12. jna
  13. AngularJS创建新指令directive参数说明
  14. jQuery选择器---层次选择器总结
  15. PLSQL(1)
  16. 关于WQS二分算法以及其一个细节证明
  17. python3学习笔记九(if语句)
  18. 如何实现从 Redis 中订阅消息转发到 WebSocket 客户端
  19. ionic3安卓版release发布
  20. Django:model中的ForeignKey理解

热门文章

  1. XP系统中IIS访问无法显示网页,目前访问网站的用户过多。终极解决办法
  2. Android Wear - Design Principles for Android Wear(设计原则)
  3. python学习之路-第四天-模块
  4. java多线程总结(二)
  5. dymaic方式的Json序列化
  6. HDU 1501 Zipper 【DFS+剪枝】
  7. HDU - 1151 Air Raid (最小路径覆盖)
  8. LigerUI LigerGird IE7/8 下不显示 “in”的操作数无效
  9. DATEDIFF() 返回2个日期之间的间隔
  10. MySQL行级锁和表级锁