黑板游戏:

We are given non-negative integers nums[i] which are written on a chalkboard. Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses. (Also, we'll say the bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.)

Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.

Return True if and only if Alice wins the game, assuming both players play optimally.

样例:

Input: nums = [1, 1, 2]
Output: false

Python:

  1. class Solution:
  2. """
  3. @param nums: a list of integers
  4. @return: return a boolean
  5. """
  6. def xorGame(self, nums):
  7. # write your code here
  8. result = 0
  9. for i in nums:
  10. result = result ^ i
  11. if result == 0 or len(nums) % 2 == 0:
  12. return True
  13. else:
  14. return False

LintCode——Chalkboard XOR Game(黑板游戏)的更多相关文章

  1. [LeetCode] Chalkboard XOR Game 黑板亦或游戏

    We are given non-negative integers nums[i] which are written on a chalkboard.  Alice and Bob take tu ...

  2. [Swift]LeetCode810. 黑板异或游戏 | Chalkboard XOR Game

    We are given non-negative integers nums[i] which are written on a chalkboard.  Alice and Bob take tu ...

  3. Weekly Contest 78-------->810. Chalkboard XOR Game

    We are given non-negative integers nums[i] which are written on a chalkboard.  Alice and Bob take tu ...

  4. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  5. HDU 5715 XOR 游戏 二分+字典树

    XOR 游戏 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5715 Description 众所周知,度度熊喜欢XOR运算(XOR百科). 今天,它 ...

  6. ARC122D XOR Game(博弈论?字典树,贪心)

    题面 ARC122D XOR Game 黑板上有 2 N 2N 2N 个数,第 i i i 个数为 A i A_i Ai​. O I D \rm OID OID(OneInDark) 和 H I D ...

  7. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

  8. 【LeetCode】数学(共106题)

    [2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...

  9. 百度之星复赛 1004 / hdu5715 二分dp+trie

    XOR 游戏 Problem Description   众所周知,度度熊喜欢XOR运算[(XOR百科)](http://baike.baidu.com/view/674171.htm). 今天,它发 ...

随机推荐

  1. orcl 中upper()和lower()和initcap()的用法

    upper(字符串 | 列):输入的字符串变为大写返回: 将 bqh4表里的zym字段信息中含有字母的全部转成大写的方法: select * from bqh4 select upper(zym) f ...

  2. 按ctrl+shift切换不了输入法

    解决方法: 1.在任务栏上的输入法图标上点右键选择设置2.选择键设置,双击第一个“在不同的输入语言之间切换”先勾选“切换输入语言”下面选择左手ALT.取消右边“切换键盘布局”前的勾3.进入“中文(简体 ...

  3. 1.1环境的准备(一)之Python解释器的安装

    目录: 1.Python-解释器的下载 2.Python-解释器的安装 3.Python-解释器的测试 4.Python的环境变量的配置 (一)Python解释器的安装: 1.官网:https://w ...

  4. 8.2Solr API使用(Facet查询)

    转载请出自出处:http://eksliang.iteye.com/blog/2165882 一)概述 Facet是solr的高级搜索功能之一,可以给用户提供更友好的搜索体验.在搜索关键字的同时,能够 ...

  5. python第三十四课——2.匿名函数配合容器函数的使用

    匿名函数配合容器函数的使用(了解) 1.匿名函数配合列表对象使用 lt=[lambda x:x**2,lambda x:x**3,lambda x:x**4] for i in lt: print(i ...

  6. 友盟推送SDK集成测试、常见问题以及注意事项总结

    最近为了解决公司APP在一些手机出现的推送问题重新集成了最新版的友盟推送SDK,花费了几天时间终于把集成和测试工作完成,最终在华为,Nexus,三星,小米,HTC,魅族等10多部手机上测试并达到了预想 ...

  7. 【Git123】Git

    https://www.cnblogs.com/jager/p/6684637.html 四.git工作原理 这边文章介绍的不错 Git from the Bottom Up 六.git常用命令 wo ...

  8. HDU 3861 The King’s Problem(tarjan缩点+最小路径覆盖:sig-最大二分匹配数,经典题)

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. Linux线程的信号量同步

    信号量和互斥锁(mutex)的区别:互斥锁只允许一个线程进入临界区,而信号量允许多个线程同时进入临界区. 不多做解释,要使用信号量同步,需要包含头文件semaphore.h. 主要用到的函数: int ...

  10. 20155209林虹宇逆向及Bof基础实验报告

    20155209林虹宇逆向及Bof基础实验报告 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符 ...