Project Euler:Problem 90 Cube digit pairs
来源:互联网 发布:猎天使魔女 知乎 编辑:程序博客网 时间:2024/05/16 12:50
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?
本来想用C++写,但是set<vector<int>>太磨人了┑( ̄Д  ̄)┍
还是python好
from itertools import combinationssquares=[(0,1),(0,4),(0,6),(1,6),(2,5),(3,6),(4,6),(8,1)]dice=list(combinations([0,1,2,3,4,5,6,7,8,6],6))def valid(c1,c2): return all(x in c1 and y in c2 or x in c2 and y in c1 for x,y in squares)ans=sum(1 for i,c1 in enumerate(dice) for c2 in dice[:i] if valid(c1,c2))print('ans = ',ans)
- Project Euler:Problem 90 Cube digit pairs
- Project Euler:Problem 16 Power digit sum
- Project Euler:Problem 20 Factorial digit sum
- Project Euler:Problem 30 Digit fifth powers
- Project Euler:Problem 33 Digit cancelling fractions
- Project Euler:Problem 34 Digit factorials
- Project Euler:Problem 51 Prime digit replacements
- Project Euler:Problem 56 Powerful digit sum
- Project Euler:Problem 63 Powerful digit counts
- Project Euler:Problem 74 Digit factorial chains
- Project Euler:Problem 92 Square digit chains
- Project Euler Problem 16 Power digit sum
- Project Euler Problem 20 Factorial digit sum
- Project Euler Problem 92 Square digit chains
- projecteuler No.90 Cube digit pairs
- Project Euler:Problem 25 1000-digit Fibonacci number
- Project Euler Problem 25 1000-digit Fibonacci number
- Matlab 编程 Project Euler Problem 20 Factorial digit sum
- Big Number
- c++ 模板详解(一)
- Swift 中使用 SwiftyJSON 制作一个比特币价格 APP
- 关于DMA传输外设地址的说明
- hdu1045 Fire Net(二分图最大匹配)
- Project Euler:Problem 90 Cube digit pairs
- zoj1745 Are We There Yet?
- HDU 3681 Prison Break(状压DP + 二分)
- H.264 基础及 RTP 封包详解
- oracle数据库---sqlplus介绍
- 1027
- JS视频播放
- NYOJ 1057 寻找最大数(三)
- NSString / NSData / char* 类型之间的转换