''' 第一題: ''' num=int(input()) #設tmp是要處理的字符串 #如何按方向鍵最少,感受就只有一種方案啊. #先改編碼 dict={'ABC':(1,2),'DEF':(1,3),'GHI':(2,1),'JKL':(2,2),'MNO':(2,3), 'PQRS':(3,1),'TUV':(3,2),'WXYZ':(3,3)} last=(1,1) sum=0 for i in range(num): tmp=input() last=(1,1) sum=0 for jj in tmp: for j in dict: if jj in j: now=dict[j] break #now是jj的編碼 sum+=abs(now[0]-last[0])+abs(now[1]-last[1]) last=now
''' 第二題:棋盤 ''' #數組b的最右面少的須要數組a最左邊的搬過來 num=int(input()) list1=input().split(' ') list2=input().split(' ') for i in range(len(list1)): list1[i]=int(list1[i]) for i in range(len(list2)): list2[i]=int(list2[i]) sum=0 tmp=0 i=len(list1)-1 while i in range(len(list1)-1,-1,-1): if list1[i]<list2[i]: que=list2[i]-list1[i] #找到最前面是1的那個位 while 1: if list1[tmp]==0: tmp+=1 continue else: if list1[tmp]>=que: list1[tmp]-=que list1[i]+=que sum+=que*(tmp+i) break else: list1[i]+=list1[tmp] sum+=list1[tmp]*(tmp+i) list1[tmp]=0 break if list1[i]==list2[i]: i-=1 continue if list1[i]>list2[i]: sum+=list1[i]-list2[i] list1[i-1]+=-(list2[i]-list1[i]) list1[i]-=-(list2[i]-list1[i]) i-=1 print(sum)
print(sum)