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 ...
随机推荐
- 【题解】【数组】【Prefix Sums】【Codility】Genomic Range Query
A non-empty zero-indexed string S is given. String S consists of N characters from the set of upper- ...
- dedecms内容页 上下篇 添加文章描述方法
dedecms5.7修改后 运行正常! 在根目录include文件夹中修改arc.archives.class.php文件,812行左右:为$query添加查询字段arc.description,分别 ...
- php 在客户端生成txt文件并且下载
在访问php时生成txt文件 $filename = 'file.text'; //也可以是其他后缀格式的 $ua = $_SERVER["HTTP_USER_AGENT"]; f ...
- Android内存管理机制之一:low memory killer
转载自http://www.miui.com/thread-29268-1-1.html 准备写这个专题之前,心里是有点忐忑的.首先Android内存管理机制相当复杂,想要讲清楚比较困难:其次对于绝大 ...
- Sprint第二个冲刺(第一天)
因为人员变动关系,我们的博客推迟了两天发布,希望老师能够谅解. 现在“广商百货”团队项目的新的团队成员组成为:董婷婷(组长).容杰龙.卓炜杰.袁文洪和吴建明 在经过第一轮和几天的休息,现在我们准备开始 ...
- SQLite 字段类型
一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存入值自动判断. SQLite具有以下五种数据类型: 1.NULL:空值. 2.INTEGER:带符号的整型,具体取决有存入 ...
- hdu1059 Dividing ——多重背包
link:http://acm.hdu.edu.cn/showproblem.php?pid=1059 最简单的那种 #include <iostream> #include <cs ...
- ubuntu 以root 运行程序
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- User_Agent_List 浏览器信息列表
User_Agent_List = ['Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHT ...
- linux下单节点oracle数据库间ogg搭建
环境说明: linux为Linux 2.6.32-573.el6.x86_64 oracle为 11g Enterprise Edition Release 11.2.0.1.0 - 64 ...