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 ...
随机推荐
- 详解for循环(各种用法)
常见的for循环一般是一下代码这种结构: for (int i = 0; i < 100; i++){ Console.WriteLine(i);} 或者递减的: ...
- java script 闭包
闭包的概念真的是很绕,我就来点实际的代码. 当我用下面的代码的时候 发生了闭包,当执行onclick事件的时候,变量一直引用了外部函数的变量,结果i总是4 function newLoad() { / ...
- TCP三次握手连接与四次握手断开
http://blog.csdn.net/whuslei/article/details/6667471(三次握手与四次握手) 1. TCP的三次握手最主要是防止已过期的连接再次传到被连接的主机. 如 ...
- 理解 %IOWAIT (%WIO)
%iowait 是 “sar -u” 等工具检查CPU使用率时显示的一个指标,在Linux上显示为 %iowait,在有的Unix版本上显示为 %wio,含义都是一样的,这个指标常常被误读,很多人把它 ...
- HQL查询语言的使用介绍
@SuppressWarnings("deprecation") public class HibernateUtil { private static final Session ...
- C#术语
数字代码.文本代码.机器码.托管代码.中间语言(IL).即时编译(JIT).COM(+).应用程序域.地址控件.虚拟内存
- windows7下python3.4.3 添加库路径(转)
1, 动态的添加库路径.在程序运行过程中修改sys.path的值,添加自己的库路径import syssys.path.append(r'your_path') 2, 在Python安装目录下的\Li ...
- POJ1637 Sightseeing tour (混合图欧拉回路)(网络流)
Sightseeing tour Time Limit: 1000MS Me ...
- P188 实战练习(父类和子类)
1.创建一个父类,在父类中创建两个方法,在子类中覆盖第二个方法,为子类创建一个对象,将它向上转型到基类并调用这个方法. 创建Computer父类: package org.hanqi.practise ...
- cve-2015-1635 poc
import socket import random ipAddr = "10.1.89.20" hexAllFfff = " req1 = "GET / H ...