Project Euler 90:Cube digit pairs 立方体数字对
Each of the six faces on a cube has a different digit (0 to 9) written on it; the same is done to a second cube. By placing the two cubes side-by-side in different positions we can form a variety of 2-digit numbers.
For example, the square number 64 could be formed:

In fact, by carefully choosing the digits on both cubes it is possible to display all of the square numbers below one-hundred: 01, 04, 09, 16, 25, 36, 49, 64, and 81.
For example, one way this can be achieved is by placing {0, 5, 6, 7, 8, 9} on one cube and {1, 2, 3, 4, 8, 9} on the other cube.
However, for this problem we shall allow the 6 or 9 to be turned upside-down so that an arrangement like {0, 5, 6, 7, 8, 9} and {1, 2, 3, 4, 6, 7} allows for all nine square numbers to be displayed; otherwise it would be impossible to obtain 09.
In determining a distinct arrangement we are interested in the digits on each cube, not the order.
{1, 2, 3, 4, 5, 6} is equivalent to {3, 6, 4, 1, 2, 5}
{1, 2, 3, 4, 5, 6} is distinct from {1, 2, 3, 4, 5, 9}
But because we are allowing 6 and 9 to be reversed, the two distinct sets in the last example both represent the extended set {1, 2, 3, 4, 5, 6, 9} for the purpose of forming 2-digit numbers.
How many distinct arrangements of the two cubes allow for all of the square numbers to be displayed?
在一个立方体的六个面上分别标上不同的数字(从0到9),对另一个立方体也如法炮制。将这两个立方体按不同的方向并排摆放,我们可以得到各种各样的两位数。
例如,平方数64可以通过这样摆放获得:

事实上,通过仔细地选择两个立方体上的数字,我们可以摆放出所有小于100的平方数:01、04、09、16、25、36、49、64和81。
例如,其中一种方式就是在一个立方体上标上{0, 5, 6, 7, 8, 9},在另一个立方体上标上{1, 2, 3, 4, 8, 9}。
在这个问题中,我们允许将标有6或9的面颠倒过来互相表示,只有这样,如{0, 5, 6, 7, 8, 9}和{1, 2, 3, 4, 6, 7}这样本来无法表示09的标法,才能够摆放出全部九个平方数。
在考虑什么是不同的标法时,我们关注的是立方体上有哪些数字,而不关心它们的顺序。
{1, 2, 3, 4, 5, 6}等价于{3, 6, 4, 1, 2, 5}
{1, 2, 3, 4, 5, 6}不同于{1, 2, 3, 4, 5, 9}
但因为我们允许在摆放两位数时将6和9颠倒过来互相表示,这个例子中的两个不同的集合都可以代表拓展集{1, 2, 3, 4, 5, 6, 9}。
对这两个立方体有多少中不同的标法可以摆放出所有的平方数?
解题
我发现这个翻译我理解不透
在两个六面体上面涂:0-9的数字,主要这里有10个数字,只用其中6个图,两个六面体涂的数字可以不一样的,6可以当9用,9可以当6用。
两个六面体上面的数字能组合成:1-9的平方:01 04 09 16 25 36 49 64 81 ,求这样的涂法有多少种?
骰子说成六面体还吊的。
0-9 十个数 取出6个 就是一个骰子的涂法。
先组合出涂法的种类。
再判断是否能组成1-9的平方
# coding=gbk import time as time
from itertools import combinations
def run():
dice=list(combinations([0,1,2,3,4,5,6,7,8,6],6))
ans = 0
for i1,d1 in enumerate(dice):
for d2 in dice[i1:]:
if valid(d1,d2) == True:
ans +=1
print ans def valid(c1,c2):
squares=[(0,1),(0,4),(0,6),(1,6),(2,5),(3,6),(4,6),(8,1)]
return all(x in c1 and y in c2 or x in c2 and y in c1 for x,y in squares) t0 = time.time()
run()
t1 = time.time()
print "running time=",(t1-t0),"s"
# 1217
# running time= 0.0620000362396 s
Project Euler 90:Cube digit pairs 立方体数字对的更多相关文章
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
- Project Euler 92:Square digit chains C++
A number chain is created by continuously adding the square of the digits in a number to form a new ...
- Project Euler 20 Factorial digit sum( 大数乘法 )
题意:求出100!的各位数字和. /************************************************************************* > Fil ...
- Project Euler 16 Power digit sum( 大数乘法 )
题意: 215 = 32768,而32768的各位数字之和是 3 + 2 + 7 + 6 + 8 = 26. 21000的各位数字之和是多少? 思路:大数乘法,计算 210 × 100 可加速计算,每 ...
- Project Euler 51: Prime digit replacements
通过替换*3这样一个两位数的第一位,我们可以发现形成的九个数字有六个是质数,即13, 23,43,53,73,83.类似的,如果我们用同样的数字替换56**3这样一个五位数的第三位和第四位,会生成56 ...
- Project Euler 56: Powerful digit sum
一个古戈尔也就是\(10^{100}\)是一个天文数字,一后面跟着一百个零.\(100^{100}\)更是难以想像的大,一后面跟着两百个零.但是尽管这个数字很大,它们各位数字的和却只等于一.考虑两个自 ...
- Project Euler 63: Powerful digit counts
五位数\(16807=7^5\)也是一个五次幂,同样的,九位数\(134217728=8^9\)也是一个九次幂.求有多少个\(n\)位正整数同时也是\(n\)次幂? 分析:设题目要求的幂的底为\(n\ ...
- Project Euler Problem 16-Power digit sum
直接python搞过.没啥好办法.看了下别人做的,多数也是大数乘法搞过. 如果用大数做的话,c++写的话,fft优化大数乘法,然后快速幂一下就好了.
- Python练习题 044:Project Euler 016:乘方结果各个数值之和
本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...
随机推荐
- ASP.ENT Core Linux 下 为 donet创建守护进程(转载)
原文地址:http://www.cnblogs.com/savorboard/p/dotnetcore-supervisor.html 前言 在上篇文章中介绍了如何在 Docker 容器中部署我们的 ...
- Java IO流详尽解析
流的概念和作用 学习Java IO,不得不提到的就是JavaIO流. 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...
- php 文件上传简单类---限制仅上传jpg文件
php 文件上传代码,限制只能上传jpg格式文件,也可以自行添加其它扩展名的文件. <?php /* * 图片上传类 仅限JPG格式图片 * edit by www.jbxue.com at 2 ...
- 2013-07-22 IT 要闻速记快想
### ========================= ### 如何让用户点击广告.观看广告并乐在其中?这个问题的答案精彩纷呈.有的公司开创模式,为点击广告的用户提供优惠券:有的公司想法新奇,让用 ...
- 在Centos7上安装漏洞扫描软件Nessus
本文摘要:简单叙述了在Centos7上安装Nessus扫描器的过程 Nessus 是目前全世界最多人使用的系统漏洞扫描与分析软件,Nessus的用户界面是基于Web界面来访问Nessus漏洞扫描器 ...
- 非常有用!eclipse与myeclipse恢复已删除的文件和代码
eclipse与myeclipse恢复已删除的文件和代码 今天写了1300多行代码,被不小心删除了顿时感觉手足无措,后来用myeclipse的历史文件恢复功能,找回来了,虚惊一场!!!MyEclip ...
- Perceptron Learning Algorithm (PLA)
Perceptron - 感知机,是一种二元线性分类器,它通过对特征向量的加权求和,并把这个”和”与事先设定的门槛值(threshold)做比较,高于门槛值的输出1,低于门槛值的输出-1.其中sign ...
- OpenWrt刷机后LAN口无法连通的问题
[路由器开发板硬件固件配置] MTK双频:MT7620a + MT7612e 内存:256 MB 闪存:16 MB 固件:MTK自带SDK中的OpenWrt固件(mtksdk-openwrt-2.6. ...
- .net 自然排序方式
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- python pip和easy_install使用方式(转载)
easy_install 跟 pip 都是Python 的套件管理程式,有了它们,在使用 Python 开发程式的时候会带来不少方便. easy_install 和pip 有什麼不一样?据 pip 官 ...