生氣的結果比生氣的原因來的嚴重!!!!
總網頁瀏覽量
2022年3月14日 星期一
2022年3月1日 星期二
2022年2月23日 星期三
A={0,1,2},以S={(x,y,z)|x,y,z屬於A}的元素為頂點,可做多少個正三角形?
Python Code:
s=[]
for x in range(1,4):
for y in range(1,4):
for z in range(1,4):
s.append([x,y,z])
flag=0
z=[]
for i in range(len(s)-2):
for j in range(i+1,len(s)-1):
for k in range(j+1,len(s)):
a1=(s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2+(s[i][2]-s[j][2])**2
a2=(s[i][0]-s[k][0])**2+(s[i][1]-s[k][1])**2+(s[i][2]-s[k][2])**2
a3=(s[j][0]-s[k][0])**2+(s[j][1]-s[k][1])**2+(s[j][2]-s[k][2])**2
if a1==a2 and a2==a3:
flag+=1
print(s[i],s[j],s[k])
print(flag)
2022年2月14日 星期一
求2個俄國人,3個美國人,2個台灣人排一列,美俄不相鄰的排法數?
頗符合現在時勢的,美俄開戰的可能性很大.....
Python Code:
import itertools
w=['r1','r2','a1','a2','a3','t1','t2']
n=list(set(itertools.permutations(w))) #排列並去除相同元素
other=[]
for i in range(len(n)):
for j in range(len(n[0])-1):
if ((n[i][j]=='r1' and n[i][j+1]=='a1') or (n[i][j]=='a1' and n[i][j+1]=='r1')) or \
((n[i][j]=='r1' and n[i][j+1]=='a2') or (n[i][j]=='a2' and n[i][j+1]=='r1')) or\
((n[i][j]=='r1' and n[i][j+1]=='a3') or (n[i][j]=='a3' and n[i][j+1]=='r1')) or\
((n[i][j]=='r2' and n[i][j+1]=='a1') or (n[i][j]=='a1' and n[i][j+1]=='r2')) or \
((n[i][j]=='r2' and n[i][j+1]=='a2') or (n[i][j]=='a2' and n[i][j+1]=='r2')) or \
((n[i][j]=='r2' and n[i][j+1]=='a3') or (n[i][j]=='a3' and n[i][j+1]=='r2')):
other.append(n[i])
ans=set(n)-set(other)
print(ans)
print(len(ans))
答案:360種
2022年2月13日 星期日
「跳針跳針跳針叫我姐姐」排成一列,「跳」與「針」不相鄰的排列數有多少種?
Python Code:
import itertools
w=['a','a','a','b','b','b','c','d','e','e']
num=list(set(itertools.permutations(w))) #排列並去除相同元素
other=[]
for i in range(len(num)):
for j in range(len(num[0])-1):
if (num[i][j]=='a' and num[i][j+1]=='b') or \
(num[i][j]=='b' and num[i][j+1]=='a'):
other.append((num[i]))
ans=set(num)-set(other)
print(ans)
print(len(ans))
答案:4080種
2022年2月11日 星期五
甲~己共6人,甲不排12位、乙不排23位、丙不排31位,求排法數?(2022.2.13日)
Python Code:
import itertools
w=['a','b','c','d','e','f']
num=list(set(itertools.permutations(w))) #排列並去除相同元素
other=[]
for i in range(len(num)):
for j in range(len(num[0])):
if num[i][0]=='a' or num[i][1]=='a' or num[i][1]=='b' or num[i][2]=='b'\
or num[i][2]=='c' or num[i][0]=='c':
other.append(num[i])
ans=set(num)-set(other)
print(ans)
print(len(ans))
答案:204種
Q:若原條件加上丁戊不相鄰,求排法數?
Python Code:
import itertools
w=['a','b','c','d','e','f']
num=list(set(itertools.permutations(w))) #排列並去除相同元素
other=[]
for i in range(len(num)):
for j in range(len(num[0])):
if num[i][0]=='a' or num[i][1]=='a' or num[i][1]=='b' or \
num[i][2]=='b'or num[i][2]=='c' or num[i][0]=='c':
other.append(num[i])
preans=set(num)-set(other)
preans=list(preans)
another=[]
for i in range(len(preans)):
for j in range(0,len(preans[0])-1):
if (preans[i][j]=='d' and preans[i][j+1]=='e') or \
(preans[i][j]=='e' and preans[i][j+1]=='d'):
another.append(preans[i])
ans=set(preans)-set(another)
print(ans)
print(len(ans))
答案:128種
2022年2月9日 星期三
8個字母a,a,b,b,b,c,c,d排成一列,求同字不相鄰的排法數有幾種?(2021.02.09)
Python Code:
import itertools
list1=input('請輸入n個要排列的數,以空格分開==> ').split()
w=[]
w=[str(x) for x in list1] #將輸入的字改成串列
num=set(itertools.permutations(w)) #排列並去除相同元素
num=list(num)#轉成串列
other=[]#儲存有相同物的排列元素
for i in range(len(num)):#有相同字的排列拿出來另存
for j in range(0,len(num[0])-1):
if num[i][j]==num[i][j+1]:
other.append(num[i])
print(num)#列出所有排列
ans=set(num)-set(other)
print(ans)#列出同字不相鄰的排列
print(len(ans))#印出同字不相鄰的方法數
答案:384種
$這題用手算真的很難討論,哥是偷懶兼投降才用Python來解它$