# 彰商校內程式設計競賽 參考答案 以下為python參考解法,以下保證能在zerojudge上完全答對 ## :memo: 參考答案 ### A.北極熊大遷徒 #### 問題敘述  因為全球暖化的關係,北極各處的浮冰正在慢慢融化之中。部份北極熊所在的浮冰已經融 化到不堪居住的程度,於是這些北極熊興起遷徙的念頭。 已經融化到不堪居住的浮冰 A 上有 a 隻北極熊,牠們現在打算遷徙到有 b 隻北極熊居住的 浮冰 B。你要回答的是:經過北極熊大遷徙以後,浮冰 B 上總共會有多少隻北極熊。 (zerojudge上不公開題目) #### 輸入格式 輸入只有一行,有兩個整數 a 和 b,代表有 a 隻北極熊即將從浮冰 A 遷徙到原本有 b 隻北 極熊的浮冰 B。  範例輸入 1 24 47 範例輸出 1 71 範例輸入2 33 20 範例輸出2 53 #### 解題絲路 題目中說明,要將A浮冰上的熊遷到B浮冰上,也就是說B浮冰上是原有的B隻+A浮冰上的熊 B=A+B #### 參考解法 ```python=1 a,b=map(int,input().split()) print(a+b) ``` 出處:2021NPSC網際網路程式大賽高中組 ### B.山六九遊樂園(https://zerojudge.tw/ShowProblem?problemid=d460) #### 解題絲路 依題目說明 0 ~ 5 歲兒童免票 兒童票 (6 ~ 11 歲):590 元 青少年票 (12 ~ 17 歲):790 元 成人票 (18 ~ 59 歲):890 元 敬老票 (60歲以上):399 元 設定一個變數A,依照題目判斷金額 #### 參考解法 ```python=1 a=int(input()) if a<6: print(0) #如果a小於6 金額為0 elif a<12: print(590) #如果a小於12且大於等於6 金額為590 elif a<18: print(790) #如果a小於18且大於等於12 金額為790 elif a<60: print(890) #如果a小於6且大於等於18 金額為890 else: print(399) #超過60歲 金額為399 ``` 出處:zerojudge d460 ### A.三角形辨別 (https://zerojudge.tw/ShowProblem?problemid=c294) 解題絲路: 第一 a,b,c為三個線段的邊長,但請注意,c為最大值,也就是說a,b,c必須由小到大排序 範例2 101 100 99 a,b,c要改成 99,100,101 可以透過list中的sort由小到大排序 ```python=1 import sys def isPerfect(num): end = int(num ** 0.5) res = end ** 2 if res == num: res = 1 - end else: res = 1 for i in range(2, end + 1): if num % i == 0: res += i + num // i return res for n in sys.stdin: n = int(n) if n == 0: break temp = isPerfect(n) if temp == n: print("=%d" % n) else: if isPerfect(temp) == n: print(temp) else: print(0) ``` 4. 七言對聯(g275) https://zerojudge.tw/ShowProblem?problemid=b294 ```python=1 n=int(input()) for i in range(n): s=0 list1=[int(i) for i in input().split()] list2=[int(i) for i in input().split()] if list1[1]==list1[3] or list1[1]!=list1[5] or list2[1]==list2[3] or list2[1]!=list2[5]: print("A",end="") s=1 if list1[6]!=1 or list2[6]!=0: print("B",end="") s=1 if list1[1]==list2[1] or list1[3]==list2[3] or list1[5]==list2[5]: print('C',end="") s=1 if s==0: print("None") print() ``` 5.洗牌(Cards)https://zerojudge.tw/ShowProblem?problemid=g797 ```python=1 n,m=map(int,input().split()) list1=[int(i) for i in input().split()] if m%2==0: a=m//2 else: a=m//2+1 list3=list1 for i in range(a): list2=[] for j in range(n//2): list2.append(list3[j]) list2.append(list3[(n//2)+j]) list3=[] for j in range(n//2): list3.append(list2[j]) list3.append(list2[(n//2)+j]) if m%2==0: for i in list3: print(i,end=" ") else: for i in list2: print(i,end=" ") ``` 6.小群體 c291 https://zerojudge.tw/ShowProblem?problemid=c291 ```python=1 n=int(input()) list1=[0]*n list2=[int(i) for i in input().split()] f=0 for i in range(n): if list1[i]==0: if list2[i]==i: list1[i]=1 f+=1 else: nex=i while list1[nex]==0: list1[nex]=1 nex=list2[nex] f+=1 print(f) ``` AC賽前預測 1. AC(7/12) 2. AC(6/12) 3. AC(5/12) 4. AC(6/12) 5. AC(3/12) 6. AC(1/12)