HackerRank "Manasa and Prime game"
Intuitive one to learn about Grundy basic :)
Now every pile becomes a game, so we need to use Sprague-Grundy Theory. Calculation is quite intuitive - and if you print them out, you will find these Grundy numbers loops by 9.
def firstMissing(s):
ret = 0
while 1:
if ret not in s: break
else: ret += 1
return ret primes = [2,3,5,7,11,13]
def grundy(v):
if v <= 2: return 0 tmp = set([])
for p in primes:
if p >= v: break
else: tmp.add(grundy(v - p))
ret = firstMissing(tmp)
grundySet[v] = ret
return ret ####################
def simpleGrundy(v):
return [0,0,1,1,2,2,3,3,4][v%9] ####################
T = int(input())
for _ in range(T):
N = int(input())
A = map(int, input().split())
sg = map(simpleGrundy, A)
ret = 0
for g in sg: ret ^= g
print(['Sandy','Manasa'][ret!=0])
HackerRank "Manasa and Prime game"的更多相关文章
- [hackerrank]Manasa and Stones
https://www.hackerrank.com/contests/w2/challenges/manasa-and-stones 简单题. #include<iostream> us ...
- 【HackerRank】Manasa and Stones
Change language : Manasa 和 她的朋友出去徒步旅行.她发现一条小河里边顺序排列着带有数值的石头.她开始沿河而走,发现相邻两个石头上的数值增加 a 或者 b. 这条小河的尽头有一 ...
- Prime triplets (Project Euler 196)
original version hackerrank programming version 题目大意是定义了一个正整数的表,第一行是1,第二行是1,2,第三行1,2,3...定义prime tri ...
- Java 素数 prime numbers-LeetCode 204
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- Prime Generator
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- UVa 524 Prime Ring Problem(回溯法)
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
- hdu 5901 count prime & code vs 3223 素数密度
hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...
随机推荐
- 关于IE6浮动问题!
以下内容均为个人笔记:望批评指教! IE6下应尽量少使用float 而是 换用display:inline 父层使用text-align:text:效果会好些: 如果一组浮动元素 产生了浮动 最好 ...
- 循环列表的Java实现,解决约瑟夫环问题
import java.util.Scanner; /** * 循环列表的Java实现,解决约瑟夫环问题 * * @author LIU * */ public class LinkedList { ...
- MariaDB exists 学习
MariaDB exists 学习 exists对外表用loop逐条查询,每次查询都会查看exists的条件语句,当 exists里的条件语句能够返回记录行时(无论记录行是的多少,只要能返回),条件就 ...
- Ubuntu 13.10下Hadoop 2.2 安装、配置、编译(伪分布式)
1.安装JDK.在此不做解说,上篇博文里已介绍过.http://www.cnblogs.com/lifeinsmile/p/3578677.html 2.配置ssh. ssh服务,用于管理远程Hado ...
- 225. Implement Stack using Queues
代码如下: class MyStack { // Push element x onto stack. Queue<Integer> queue=new ArrayDeque<> ...
- break、continue与return见的区别
比较简单的说法就是: 1.break:跳出当前的循环体 2.continue:跳出本次的循环 3.return:返回调用函数(也就完全的跳出了函数块) 好,下面就是我的代码练习君了: package ...
- android默认浏览器response下载PDF文件
下载出来的文件不是PDF,而是xxx.htm文件,原因是response的header配置有问题. android默认浏览器的情况下,header的配置应该写成.(java 为例) response. ...
- AttributeError: 'NoneType' object has no attribute 'bytes' python3.4 win64
解决方法: easy_install -U pip 详见: https://github.com/pypa/pip/issues/2669
- Python学习(1)
幂运算符比取反(一元运算符)的优先级要高. >>>-3**2 -9 >>>(-3)**2 9 >>>pow(2,3) 8 abs函数可以得到数的绝 ...
- 越狱Season 1-Season 1, Episode 3: Cell Test
Season 1, Episode 3: Cell Test -CO: Oh, my God. 我的天 Williamson, get in here. Williamson 快进来 What the ...