取石子游戏

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7192    Accepted Submission(s): 4313

Problem Description
1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win".
 
Input
输入有多组.每组第1行是2<=n<2^31. n=0退出.
 
Output
先取者负输出"Second win". 先取者胜输出"First win". 
参看Sample Output.
 
Sample Input
2
13
10000
0
 
Sample Output
Second win
Second win
First win
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2509 2512 1536 2510 1907 
 
寻找规律可以知道,必败的情况下都是斐波那契数,所以做一匹配就可以了,使用离线和二分法搜索来提高效率。

 #include<bits/stdc++.h>
using namespace std; long long fs[]; void init() {
fs[] = ;
fs[] = ; for(int i = ; i <= ;i ++) {
fs[i] = fs[i-] + fs[i-];
}
} bool find(long long n) {
int l = ;
int r = ;
int mid = (l+r) >> ; // (l+r)/2
while(l <= r) {
if(fs[mid] == n) return true;
else if(fs[mid] < n) l = mid + ;
else r = mid - ;
mid = (l+r) >> ;
}
return false;
} int main() { init();
long long n;
while(~scanf("%lld",&n)&&n) {
if(find(n)) puts("Second win");
else puts("First win");
}
return ;
}
 

【博弈】【HDU】取石子游戏的更多相关文章

  1. HDU.2516 取石子游戏 (博弈论 斐波那契博弈)

    HDU.2516 取石子游戏 (博弈论 斐波那契博弈) 题意分析 简单的斐波那契博弈 博弈论快速入门 代码总览 #include <bits/stdc++.h> #define nmax ...

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

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

  3. HDU 2516 取石子游戏(斐波那契博弈)

    取石子游戏 Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  4. HDU 2516 取石子游戏(FIB博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. hdu 2516 取石子游戏 (博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. hdu 2516 取石子游戏 (Fibonacci博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. 取石子游戏(hdu1527 博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. POJ.1067 取石子游戏 (博弈论 威佐夫博弈)

    POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...

  9. poj 1067 取石子游戏 (威佐夫博弈)

    取石子游戏 http://poj.org/problem?id=1067 Time Limit: 1000MS   Memory Limit: 10000K       Description 有两堆 ...

随机推荐

  1. ActiveMQ学习系列(二)----生产者客户端(java)

    上文主要简单地将activeMq搭建了起来,并且可以用web console去登录查看相关的后台功能. 本文将学习如何用java语言实现一个生产者客户端,主要参考了以下链接: http://activ ...

  2. Qt自定义控件

    Qt创建自定义控件教程 一.新建Qt设计师控件 二.设置项目名称 三.选择kits 这里取消Debug选项,不需要这个选项都是编译为dll文件直接调用. 删除掉MyControl原有的.h和cpp文件 ...

  3. anguar使用指令写选项卡

    今天,我们来学习一下angular中怎么使用指令来实现两个选项卡的问题. 首先,要先引入jQuery文件与angularjs文件. <!DOCTYPE html><html lang ...

  4. 1020关于MYCAT的安装和使用总结

    第一部分 读写分离配置 转自:http://www.51testing.com/html/34/369434-3686088.html 使用Mycat 做简单的读写分离(一) 原本使用的是amoeba ...

  5. WPF中自定义GridLengthAnimation

    需求 我们想在编辑一个列表中某一个条目时,将编辑的详情内容也放置当前面,比如右侧. 可以通过将一个Grid,分成两个Cloumn,动态调整两个Cloumn的Width,就可以实现这个需求. 我们知道, ...

  6. ES6 new syntax of let and const (one)

    variable declarations : let, const,and block scope why we redefine the way about declarations? funct ...

  7. [LeetCode] Redundant Connection 冗余的连接

    In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...

  8. [LeetCode] Construct the Rectangle 构建矩形

    For a web developer, it is very important to know how to design a web page's size. So, given a speci ...

  9. 机器学习技法:12 Neural Network

    Roadmap Motivation Neural Network Hypothesis Neural Network Learning Optimization and Regularization ...

  10. 页面中引入mui 地址选择,点击页面中其他input时页面回到顶部

    问题:在页面中引入mui地址选择时,点击页面中的input页面会滚到顶部(谷歌浏览器中出现的bug),在手机上点击input会出现跳动.开始的时候是想修改mui.min.js里的滚动事件,但是后来找到 ...