LeetCode: 292 Nim Game(easy)
题目:
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.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
代码:
class Solution {
public:
bool canWinNim(int n) {
return (n% != );
}
};
LeetCode: 292 Nim Game(easy)的更多相关文章
- LN : leetcode 292 Nim Game
lc 292 Nim Game 292 Nim Game You are playing the following Nim Game with your friend: There is a hea ...
- 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 ...
- 292. Nim Game(easy)
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 ...
随机推荐
- linux c 网络编程:用域名获取IP地址或者用IP获取域名 网络地址转换成整型 主机字符顺序与网络字节顺序的转换
用域名获取IP地址或者用IP获取域名 #include<stdio.h> #include<sys/socket.h> #include<netdb.h> int ...
- SecureCRT 7.0 如何自动记录日志
设置步骤如下: 1.打开SecureCRT ,在菜单里选择“选项”-->“全局选项” 2.然后选择“常规”--> “默认会话”--> “编辑默认设置” 3.然后选择“日志 ...
- ubuntu 单网卡双 ip
局域网一套物理网络里有两个 ip 段,单网卡设置多 ip 可实现同时访问两个网段. $ cat /etc/network/interfaces # interfaces(5) file used by ...
- 阿里云nginx+thinkphp环境运行会直接下载php文件的问题。
测试了好久,在网上查了各种nginx.conf的虚拟机配置都没用 其实最简单的方法就是在php.ini中找到 #cgi.fix_pathinfo=1; 去掉前面的#,如果值不是1则改为1
- PHP网站加网站访问量统计
新建cnt.php <?php $n=file_get_contents('cnt.txt'); $n++; file_put_contents('cnt.txt',$n); echo &quo ...
- SQL创建触发器
更新: CREATE TRIGGER `r_users_1` AFTER UPDATE ON `users` FOR EACH ROW update `wxusers` set status=NEW. ...
- SQL还原数据库后,数据库显示受限制用户解决方法
数据库->属性->选项
- 百度之星2016资格赛D,水题
很简单的题,主要是要用字符串哈希,把字符串处理成整数.接下来可以继续用hash,也可以像我一样用个map就搞定了. /* * Author : ben */ #include <cstdio&g ...
- EasyDarwin开源流媒体服务器提供的TS切片/HLS直播打包库
EasyHLS Github:https://github.com/EasyDarwin/EasyHLS EasyHLS是什么? EasyHLS是EasyDarwin开源流媒体社区开发的一款HLS打 ...
- CMake命令笔记
project 为整个工程设置名称.版本和启用语言 project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])projec ...