LN : leetcode 292 Nim Game
lc 292 Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.
Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.
For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.
analysation##
Nim Game from baike
We can easily figure out that if the amount is n times as much as 4, then you will surly lose the game.
solution
bool canWinNim(int n) {
if (n%4 == 0)
return 0;
else
return 1;
}
LN : leetcode 292 Nim Game的更多相关文章
- lintcode 394. Coins in a Line 、leetcode 292. Nim Game 、lintcode 395. Coins in a Line II
变型:如果是最后拿走所有石子那个人输,则f[0] = true 394. Coins in a Line dp[n]表示n个石子,先手的人,是必胜还是必输.拿1个石子,2个石子之后都是必胜,则当前必败 ...
- Java实现 LeetCode 292 Nim游戏
292. Nim 游戏 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解 ...
- LeetCode 292. Nim Game (取物游戏)
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- LeetCode 292. Nim Game
Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...
- Java [Leetcode 292]Nim Game
问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...
- 【算法功底】LeetCode 292 Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- LeetCode 292 Nim Game 解题报告
题目要求 You are playing the following Nim Game with your friend: There is a heap of stones on the table ...
- LeetCode 292 Nim Game(Nim游戏)
翻译 你正在和你的朋友们玩以下这个Nim游戏:桌子上有一堆石头.每次你从中去掉1-3个.谁消除掉最后一个石头即为赢家.你在取出石头的第一轮. 你们中的每个人都有着聪明的头脑和绝佳的策略.写一个函数来确 ...
- [LeetCode] 292. Nim Game_Easy tag: Math
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
随机推荐
- Filter Blue Light for Better Sleep(APP 推荐)
Filter Blue Light for Better Sleep By Carolyn Mohr11 May, 2016 Many people like to use their phones ...
- 深度分析DB2修改表
DB2修改表操作相信大家都不陌生,下文对DB2修改表方面结合了一些例子进行了详细的分析讨论,供您参考学习. DB2修改表使用ALTER TABLE语句来更改列属性,例如可空性.LOB选项.作用域.约束 ...
- oracle限制用户连接数
查看是否启用限制配置 SQL> show parameter resource_limit; 或者 select * from v$parameterwhere name = 'resource ...
- SQL增加,删除,更改表中字段
1. 向表中添加新的字段 alter table table_name add column_name varchar2(20) not null 2. 删除表中的一个字段 delete t ...
- Excel 代码
package com.chinabase.common.util; import java.io.FileInputStream; import java.io.FileOutputStream; ...
- 开源项目:libbpg
1 ubuntu下编译libbpg(编译机器64bit) 安装cmake,libpng,yasm,gcc,g++ cmake版本最低为2.8.8,安装完毕后使用cmake --version查看是否安 ...
- 【MySQL】TokuDB引擎初探(MySQL升级为Percona,MySQL升级为MariaDB)
参考:http://blog.sina.com.cn/s/blog_4673e6030102v46l.html 参考:http://hcymysql.blog.51cto.com/5223301/14 ...
- 入门学习PHP之变量_1
1.函数里只能访问局部变量,不能访问全局变量,如果函数里需要访问全局变量则需要在变量前加global作用域,如下实例: <?php $x=5; $y=10; function myTest() ...
- Linux之文件系统的简单操作
df:列出文件系统整体硬盘使用量 将容量以易读方式显示: [root@zkero ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/s ...
- poj2503 哈希
这题目主要是难在字符串处理这块. #include <stdio.h> #include <string.h> #include <stdlib.h> #defin ...