--- title: 112電算第一次社內賽題解 Python版 --- # 112電算社第一次社內賽題解 Python版 --- ## 第一次社內賽2023.10.20 ### 第一題:癸卯事變 簡單粗暴 ```python= a = int(input()) b = int(input()) c = int(input()) d = 0 ans = 0 win = 0 if a > b: d = a*(a-b) win = 1 else: d = b*(b-a) win = 2 if c > d: ans = d*(c-d) win = 3 else: ans = c*(d-c) print("(",win,",",ans,")",sep = "") ``` ### 第二題:LINK START 一樣不難,於每次輸入完變數後運算即可。 ```python= k = int(input()) s0 = 0 s1 = 0 for i in range(k): a,b,c = list(map(int,input().split(' '))) s0 += a*b s1 += a*c if s0 > s1: print(s0,s1,0,sep = '\n') elif s1 > s0: print(s0,s1,1,sep = '\n') else: print(s0,s1,"tie",sep = '\n') ``` ### 第三題:儲水管理 需要有點技巧嘍~理解題目也是很重要的一環。 ```python= n = int(input()) h = list(map(int, input().split())) h1 = 0 h2 = 0 a = 1 b = 1 j = 0 for i in h: j+=1 if i > h1 and i > h2: h2 = h1 h1 = i b = a a = j elif i > h2: h2 = i b = j print(min(b,a),max(a,b)) ``` ### 第四題:晶石運送 魔王題 ```python= a=int(input()) for i in range(a): b=int(input()) x=list(map(int,input().split())) e=list(map(int,input().split())) su=sum(e) k=0 ma=-100000000000000000000 for j in range(sum(x)//b , sum(x)//b+2): k=su for t in x: k-=(j-t)**2 if k>ma: ma=k print(ma) ```