【蓝桥杯】2016初赛 剪邮票
程序员文章站
2022-05-09 21:23:23
...
题目描述
如下图, 有12张连在一起的12生肖的邮票。现在你要从中剪下5张来,要求必须是连着的。(仅仅连接一个角不算相连)
比如,下面两张图中,粉红色所示部分就是合格的剪取。
请你计算,一共有多少种不同的剪取方法。
输出
请填写表示方案数目的整数。
V暴力,枚举出任意五个,然后选出连在一起的就可以了
summ=0
xl = [[1,2],[1,5],[2,3],[2,6],[3,4],[3,7],[4,8],[5,9],[5,6],[6,7],[6,10],[7,8],[7,11],[8,12],[9,10],[10,11],[11,12]]
for x1 in range(1,13):
for x2 in range(x1+1,13):
for x3 in range(x2+1,13):
for x4 in range(x3+1,13):
for x5 in range(x4+1,13):
if [x1,x2] in xl or [x1,x3] in xl or [x1,x4] in xl or [x1,x5] in xl :
if [x1,x2] in xl or [x2,x3] in xl or [x2,x4] in xl or [x2,x5] in xl :
if [x1,x3] in xl or [x2,x3] in xl or [x3,x4] in xl or [x3,x5] in xl :
if [x1,x4] in xl or [x2,x4] in xl or [x3,x4] in xl or [x4,x5] in xl :
if [x1,x5] in xl or [x2,x5] in xl or [x3,x5] in xl or [x4,x5] in xl :
sum1 = ([x1,x2] in xl) + ([x1,x3] in xl) + ([x1,x4] in xl) + ([x1,x5] in xl)
sum2 = ([x2,x3] in xl) + ([x2,x4] in xl) + ([x2,x5] in xl)
sum3 = ([x3,x4] in xl) + ([x3,x5] in xl)
sum4 = ([x4,x5] in xl)
#print(sum1+sum2+sum3+sum4)
if sum1+sum2+sum3+sum4>=4:
summ+=1
print(summ)
上一篇: 10 WebGL的缓冲区对象使用
下一篇: JAVA中的各种Buffer