Game of Taking Stones (大数 + 威佐夫博弈 java写的)
2017-05-01 17:34
477 查看
C - Game of Taking Stones
import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { BigDecimal TWO = BigDecimal.valueOf(2); BigDecimal FIVE = BigDecimal.valueOf(5); BigDecimal EPS = new BigDecimal( "-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); BigDecimal l = new BigDecimal("2.2360679774997"), r = new BigDecimal("2.2360679774998"); BigDecimal m = null; while (l.subtract(r).compareTo(EPS) < 0) { m = l.add(r).divide(TWO); if (m.multiply(m).subtract(FIVE).abs().compareTo(EPS.abs()) < 0) break; if (m.multiply(m).subtract(FIVE).compareTo(EPS) < 0) l = m; else r = m; } BigDecimal GOLD = m.add(BigDecimal.ONE).divide(TWO); Scanner sc = new Scanner(System.in); while (sc.hasNext()) { BigDecimal a = sc.nextBigDecimal(), b = sc.nextBigDecimal(); if (a.compareTo(b) > 0) { BigDecimal t = a; a = b; b = t; } BigDecimal c = b.subtract(a).setScale(0, BigDecimal.ROUND_FLOOR).multiply(GOLD); c = c.setScale(0, BigDecimal.ROUND_FLOOR); if (a.equals(c)) System.out.println("0"); else System.out.println("1"); } sc.close(); } }
相关文章推荐
- 2016 ICPC 大连 C Game of Taking Stones 【威佐夫博弈+大数+高精度】
- hdu 5973 Game of Taking Stones java大数+根号5的精度
- Game of Taking Stones (hdu5973)——2016大连现场赛C题 威佐夫博弈
- HDU 5973-Game of Taking Stones(威佐夫博弈-JAVA BigDecimal)
- HDU 5973 Game of Taking Stones 威佐夫博弈+大数
- Game of Taking Stones(威佐夫博奕 待整理)
- Codeforces Round #399 E Game of Stones 博弈
- ZOJ 3964 Yet Another Game of Stones(Nim博弈 待整理)
- Codeforces Round #399 (Div. 1 + Div. 2, combined) (博弈,Nim游戏)E.Game of Stones
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Round #399 E Game of Stones 博弈
- HDU 5973 ICPC 大连 Game of Taking Stones
- HDOJ 5973 Game of Taking Stones
- Codeforces Round #399 E Game of Stones 博弈
- Game of Connections(大数java+Catalan数)
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces 768 E. Game of Stones 博弈DP
- [hdu 5973 Game of Taking Stones] Wythoff Game+大数运算
- codeforces 399 E. Game of Stones 博弈 思维题
- HDU 5973 Game of Taking Stones (威佐夫博弈+高精度)