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 ...
随机推荐
- Flume NG 简介及配置实战
Flume 作为 cloudera 开发的实时日志收集系统,受到了业界的认可与广泛应用.Flume 初始的发行版本目前被统称为 Flume OG(original generation),属于 clo ...
- C语言redirection
1)把执行文件xxx.exe 和读取的文件yyy.txt放在一个地方 2)用dos 命令 dir 和cd,打开存放文件的文件夹 3)window 7 情况下 输入xxx.exe < yyy.tx ...
- PAT (Basic Level) Practise:1002. 写出这个数
[题目链接] 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各 ...
- CUDA 程序中的同步
前言 在并发,多线程环境下,同步是一个很重要的环节.同步即是指进程/线程之间的执行顺序约定. 本文将介绍如何通过共享内存机制实现块内多线程之间的同步. 至于块之间的同步,需要使用到 global me ...
- 解决f.lux总是弹框定位
解决f.lux总是弹框定位,直接导入成功定位的注册表文件即可. 以下保存为f.lux.reg 双击导入即可. Windows Registry Editor Version 5.00 [HKEY_CU ...
- Sed简单入门实例
1. Sed简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后 ...
- ResponsiveSlides.js最轻量级的幻灯片插件
摘要:ResponsiveSlides.js是一个展示同一容器内图片的轻量级响应式jQuery幻灯片插件它支持包括IE6在内的几乎所有的浏览器,在IE6中还支持最大宽度属性,但在其它浏览器中并不原生支 ...
- ZOJ 1007 Numerical Summation of a Series
原题链接 题目大意:x的取值从0.000到2.000,输出每个x对应的y(x)的值 解法:参考了这篇日志http://www.cnblogs.com/godhand/archive/2010/04/2 ...
- my PhoneWeb
<meta name="viewport" content="width=device-width, user-scalable=yes, minimum-scal ...
- nginx绑定多个域名
nginx绑定多个域名涉及到的技术为url rewrite,可以先了解下知识背景再过来学习. 这里以域名:www.sample.com为例 1.在/usr/local/nginx/conf文件夹中创建 ...