總網頁瀏覽量
2019年10月4日 星期五
2019年10月3日 星期四
2015年 IMO 第二題
Python Code:
two=[]
for i in range(100):
two.append(2**i)
for a in range(1,100):
for b in range(1,100):
for c in range(1,100):
s1=a*b-c
s2=b*c-a
s3=c*a-b
if (s1>0) and (s2>0) and (s3>0):
if (s1 in two) and (s2 in two) and (s3 in two):
print(a,b,c)
答案:
2 2 3
2 3 2
2 6 11
2 11 6
3 2 2
3 5 7
3 7 5
5 3 7
5 7 3
6 2 11
6 11 2
7 3 5
7 5 3
11 2 6
11 6 2
2019年9月30日 星期一
2019年9月20日 星期五
2019年9月18日 星期三
2019年9月16日 星期一
2019 IMO(國際數學奧林匹亞數競賽) 第五題--巴斯銀行
Python Code:
import random
def hand():#手動輸入HT的初始狀態
global A #A用全域變數 後面才讀得到
A=[x for x in input()]
def givenumber(): #給一個正整數,找出H跟T
n=int(input())
B=[]
global A
global h1 # 'H'面朝上的次數
A=[]
h1=0
for i in range(n):
B.append(random.randrange(0,2*n))
for j in range(n):
if (B[j]%2)==0:
A.append('H')
else:
A.append('T')
print(A)
#hand()
givenumber()
for i in range(1000):
flag=0 #T面的個數,當flag等於len(A),即全為T時,停止
for j in range(len(A)):
if A[j]=='T':
flag+=1
if flag==len(A):
print(i)#輸出第幾次操作可得到全為T
break
h=0#計算幾個h面朝上
for k in range(len(A)):
if A[k]=='H':
h+=1
if A[h-1]=='H':#從左邊數來,將第h枚翻過來
A[h-1]='T'
else:
A[h-1]='H'
2019年9月10日 星期二
訂閱:
文章 (Atom)







