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

  1. [hackerrank]Manasa and Stones

    https://www.hackerrank.com/contests/w2/challenges/manasa-and-stones 简单题. #include<iostream> us ...

  2. 【HackerRank】Manasa and Stones

    Change language : Manasa 和 她的朋友出去徒步旅行.她发现一条小河里边顺序排列着带有数值的石头.她开始沿河而走,发现相邻两个石头上的数值增加 a 或者 b. 这条小河的尽头有一 ...

  3. Prime triplets (Project Euler 196)

    original version hackerrank programming version 题目大意是定义了一个正整数的表,第一行是1,第二行是1,2,第三行1,2,3...定义prime tri ...

  4. Java 素数 prime numbers-LeetCode 204

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  5. Prime Generator

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. UVa 524 Prime Ring Problem(回溯法)

    传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...

  8. Sicily 1444: Prime Path(BFS)

    题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...

  9. hdu 5901 count prime & code vs 3223 素数密度

    hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...

随机推荐

  1. Optimizing shaper — hashing filters (HTB)

    I have a very nice shaper in my linux box :-) How the configurator works — it’s another question, he ...

  2. CentOS 6.2 OpenVPN 搭建

    一.yum 安装. 二.下载 easy-rsa 3.0 三.生成根证书.服务器.客户端证书.ta 生成流程: wget -c https://github.com/OpenVPN/easy-rsa/a ...

  3. bootstrap-3

    段落: 1.全局文本字号为14px(font-size); 2.行高为1.42857143(line-height),大约是20px(一串数字是由less编译器计算出来的,当然sass也有这样的功能) ...

  4. html--整站制作

    1.样式初置 body,div,ul,ol,h1,h2,h3,h4,h5,p,form,input,textarea,select{margin:0;padding:0;} li{list-style ...

  5. 2层Folder删除问题,父文件夹删不掉

    在此用的是由内向外删除.文件结构是:父文件夹/子文件夹/文件.用的是java1.6的java.io.FIle#deleteFile(); 在删除的过程中,发现,文件删除的时候没有问题,但是在子文件夹删 ...

  6. Android——进度对话框

    java类代码: //普通进度对话框 public void bt8_onClick(View v) { final ProgressDialog progressDialog = new Progr ...

  7. 《灰帽Python-黑客和逆向工程师的Python编程》学习记录

    ctypes是Python语言的一个外部库,提供和C语言兼容的数据类型,可以很方便的调用C DLL中的函数. 操作环境:CentOS6.5 Python版本:2.66 ctypes是强大的,强大到本书 ...

  8. Fragment用app包还是v4包解析

    转自:http://blog.csdn.net/zc0908/article/details/50721553 1)问题简述 相信很多的朋友在调用Fragment都会遇到下面的情况: 这个时候问题来了 ...

  9. x86-64_register_and_function_frame.html

    http://www.searchtb.com/2013/03/x86-64_register_and_function_frame.html

  10. struts2获得request和session对象

    在struts1中,获得到系统的request或者session对象非常方便,都是按照形参传递的,但是在struts2中,request和session都被隐藏了 struts2提供两种方式访问ses ...