lc 292 Nim Game


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的更多相关文章

  1. 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个石子之后都是必胜,则当前必败 ...

  2. Java实现 LeetCode 292 Nim游戏

    292. Nim 游戏 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解 ...

  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 ...

  4. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  5. Java [Leetcode 292]Nim Game

    问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...

  6. 【算法功底】LeetCode 292 Nim Game

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  7. LeetCode 292 Nim Game 解题报告

    题目要求 You are playing the following Nim Game with your friend: There is a heap of stones on the table ...

  8. LeetCode 292 Nim Game(Nim游戏)

    翻译 你正在和你的朋友们玩以下这个Nim游戏:桌子上有一堆石头.每次你从中去掉1-3个.谁消除掉最后一个石头即为赢家.你在取出石头的第一轮. 你们中的每个人都有着聪明的头脑和绝佳的策略.写一个函数来确 ...

  9. [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 ...

随机推荐

  1. 解决IllegalStateException: Can not perform this action after onSaveInstanceState

    今天使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState ...

  2. JavaScript 变量克隆和判断变量类型

    一.变量克隆 在js中经常会遇到将一个变量赋值给一个新的变量这种情况,这对于基本类型很容易去实现,直接通过等号赋值就可以了,对于引用类型就不能这样了.(注:像函数,正则也可以直接通过等号赋值) 这里我 ...

  3. 读取计算机的OEM信息

    只需要读取注册表里面的值即可 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Logo 下面有制 ...

  4. Quick Sort

    class Program { static int[] a = new int[] { 6, 1, 2, 7, 9, 3, 4, 5, 10, 8 }; int n; static void Mai ...

  5. 学习总结 Java 基本数据类型 和标识符以及常用的关键字

    思维导图: public static void main(String[] args) { // java程序的入口点 c#是Main System.out.println("测试输出&q ...

  6. activity的android:name 设置问题

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com. ...

  7. 保护企业的Word文档

    保护企业的Word文档 通常,我们可以对Word文件进行加密码.设置为只读.禁止复制甚至是将内容变成图片加以保护,但这仅限于个人少量文档,如果是企业每天生产大量的word文档好用这种方法就不行,今天为 ...

  8. JDBC链接MySQL和Oracle

    import java.sql.*;         JDBC中所要用的包几乎都在import?java.sql.*;中: 在项目中导入Oracel或者是MySQL包和装载驱动:     项目的Cla ...

  9. I/O系统,多线程、图形用户界面编程

    多线程 进程与线程区别: 进程需要分配独立的内存空间:线程在同一内存空间中工作,可以共享同一块内存和系统资源 与Java相关的API: 1)Thread类 方法:start()启动: urn() : ...

  10. 开源项目:网页实时通信WebRTC

    参考资料 [博客系列] Android WebRTC 音视频开发总结 [环境编译] WebRTC入门指南 各平台WebRTC源码网盘下载 Ubuntu14.04编译WebRTC For Android ...