题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5973

Game of Taking Stones

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#### 问题描述
> 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 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.

输出

For each test data,output answer on one line.1 means you are the winner,otherwise output 0.

样例输入

2 1

8 4

4 7

样例输出

0

1

0

题解

威佐夫博弈+大数

对于a,b(a<b),如果有floor((b-a)*((sqrt(5)+1)/2))==a,则为必败态。

import java.awt.peer.SystemTrayPeer;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner; public class Main {
public static void main(String[] args) { BigDecimal two=new BigDecimal(2);
BigDecimal thr=new BigDecimal(3);
BigDecimal fiv=new BigDecimal(5); BigDecimal l=two,r=thr; for(int i=0;i<500;i++){
BigDecimal mid=r.add(l).divide(two);
if(mid.multiply(mid).compareTo(fiv)<0){
l=mid;
}else{
r=mid;
}
} BigDecimal gold=l.add(BigDecimal.ONE).divide(two); BigDecimal a,b;
Scanner cin=new Scanner(System.in); while(cin.hasNext()){
a=cin.nextBigDecimal();
b=cin.nextBigDecimal();
if(a.compareTo(b)>0){
BigDecimal tmp=a;
a=b;
b=tmp;
} BigDecimal zero=a.subtract(b.subtract(a).multiply(gold).setScale(0,BigDecimal.ROUND_FLOOR)); //100位
BigDecimal sma=new BigDecimal("0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); if(zero.abs().compareTo(sma)<0){
System.out.println("0");
}else{
System.out.println("1");
} } }
}

HDU 5973 Game of Taking Stones 威佐夫博弈+大数的更多相关文章

  1. HDU 5973 Game of Taking Stones (威佐夫博弈+高精度)

    题意:给定两堆石子,每个人可以从任意一堆拿任意个,也可以从两堆中拿相同的数量,问谁赢. 析:直接运用威佐夫博弈,floor(abs(a, b) * (sqrt(5)+1)/2) == min(a, b ...

  2. HDU 1527 取石子游戏 (威佐夫博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是 ...

  3. HDU 1527 取石子游戏(威佐夫博弈)

    基础威佐夫博弈,判断奇异局势即可,判断方式为k为两数之差绝对值,(sqrt(5) + 1) / 2 * k若等于两数小者则为奇异局势,也就是必败态. #include<stdio.h> # ...

  4. 题解报告:hdu 1527 取石子游戏(威佐夫博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石 ...

  5. HDU - 5973 Game of Taking Stones (威佐夫博弈 高精度)

    题目描述: Two people face two piles of stones and make a game. They take turns to take stones. As game r ...

  6. hdu 1527 (威佐夫博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石 ...

  7. 取石子游戏 HDU 1527 博弈论 威佐夫博弈

    取石子游戏 HDU 1527 博弈论 威佐夫博弈 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两 ...

  8. HDU 2177 取(2堆)石子游戏 (威佐夫博弈)

    题目思路:威佐夫博弈: 当当前局面[a,b]为奇异局时直接输出0 否则: 1.若a==b,输出(0 0): 2.将a,b不停减一,看能否得到奇异局,若有则输出: 3.由于 ak=q*k(q为黄金分割数 ...

  9. HDU 1527 取石子游戏(威佐夫博弈)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. Flume practices and sqoop hive 2 oracle

    #receive the file flume-ng agent --conf conf --conf-file conf1.conf --name a1 flume-ng agent --conf ...

  2. WDK编程的一些特殊点

    函数的多线程安全性在内核编程中比用户态应用程序的编程更常见. 调用源 运行环境 原因 driverEntry,DriverUnload 单线程 这两个函数由系统进程的单一线程调用,不会出现多线程同时调 ...

  3. display:-webkit-box

    Flexbox 为 display 属性赋予了一个新的值(即 box 值), flexbox的属性有很多,记录一些比较常用的属性: 用于父元素的样式: display: box; 该属性会将此元素及其 ...

  4. solr性能调优

    Schema Design Considerations indexed fields indexed fields 的数量将会影响以下的一些性能: 索引时的时候的内存使用量 索引段的合并时间 优化时 ...

  5. hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal

    #1388 : Periodic Signal 时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal proce ...

  6. JAVASE笔记回顾

    第一部分,JAVA基础和面向对象 part01 入门与开发环境搭建 1: 计算机基础知识(了解)(1)计算机(2)计算机硬件(3)计算机软件系统软件:windows,linux,mac应用软件:QQ, ...

  7. python中for和if else的使用

    In []: a = set('abcd') In []: b = set('ef') In []: def match(x,y): ....: for i in x: ....: for j in ...

  8. 2014 Super Training #9 E Destroy --树的直径+树形DP

    原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...

  9. 2014 Super Training #1 C Ice-sugar Gourd 模拟,扫描线

    原题 HDU 3363 http://acm.hdu.edu.cn/showproblem.php?pid=3363 给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半. ...

  10. 彻底解决Spring MVC 中文乱码 问题

    1:表单提交controller获得中文参数后乱码解决方案 注意: jsp页面编码设置为UTF-8 form表单提交方式为必须为post,get方式下面spring编码过滤器不起效果 <%@ p ...