HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
来源:互联网 发布:excel删除一列数据 编辑:程序博客网 时间:2024/06/07 04:02
传送门
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
题目大意:
两堆石子,分别
解题思路:
二分精度,把精度精确到一百位左右就OK了,用 java 操作比较方便, 有
代码:
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"); } }}
阅读全文
0 0
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- The 2016 ACM-ICPC Asia Dalian Regional Contest(汇总)
- HDU 5875 Function(二分区间+RMQ)——2016 ACM/ICPC Asia Regional Dalian Online
- 2016 ICPC 大连 C Game of Taking Stones 【威佐夫博弈+大数+高精度】
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest Find the maximum
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4001
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4002
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4007
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&Dave
- The 2011 ACM-ICPC Asia Dalian Regional Contest——D Hexadecimal View
- 4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)
- HDU 5874 Friends and Enemies(二分图思想)——2016 ACM/ICPC Asia Regional Dalian Online
- HDU 5973 Game of Taking Stones 博弈+高精度
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The kth great number
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The Frog's Games
- HDU-5973 Game of Taking Stones(威佐夫博弈+高精度)(C++高精度)
- 2016 ACM/ICPC Asia Regional Dalian Online 1006 football game 1007 hdu 5873 hdu 5874
- 栈应用于括号匹配
- 史上最简单的SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)
- 《露珠》(加夫列拉·米斯特拉尔)
- C++/C++11中std::list双向链表的使用
- pointer_1
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- 牛腩总结(二)
- 史上最简单的SpringCloud教程 | 第九篇: 服务链路追踪(Spring Cloud Sleuth)
- java常考笔试题2
- innodb buffer pool管理--LRU插入
- Node.js 常用工具
- 链接时重定位
- Spark学习起步(二):sparkContext
- 红黑树