google-code-jam 2019 Qualification Round Cryptopangrams

Cryptopangrams測試

神題,wa20google

主要是測試用例難設計 spa

   

簡介 設計

int T, L;code

array<int,L> arr orm

string S; ip

   

T組測試用例,每組測試用例給出arr,ci

arr由另外一個字符串S變換而成 字符串

S知足:get

  1. 元素是[A-Z]26個大寫字母, 每一個字母至少出現一次
  2. S的長度是L+1

變換方法:

首先對每一個大寫字母[A-Z]分配一個素數,分配方法是f

eg. f={'A':2,'B':89,...}

靠後的大寫字母分配到的素數更大

L= [f[S[i]]*f[S[i+1]] for i in range(L)]

   

輸入格式

L N

arr

   

輸出格式

S

   

代碼

import math

from string import ascii_uppercase as upper

T=int(input())

for t in range(1,1+T):

N,L=map(int,input().split())

cipher=list(map(int,input().split()))

   

ori=[0]*(L+1)

   

for ent in range(L):

r=int(math.sqrt(cipher[ent]))

if r**2==cipher[ent]:

ori[ent+1]=r

break

if ent!=L-1:

g=math.gcd(cipher[ent],cipher[ent+1])

if g!=cipher[ent]:

ori[ent+1]=g

break

# [0,0,<<< >>>,0,0]

for j in range(ent,0 -1,-1):

ori[j]=cipher[j]//ori[j+1]

for j in range(ent+2,L +1):

ori[j]=cipher[j-1]//ori[j-1]

   

# print(ori)

psd=sorted(set(ori))

   

trans={psd[i]: upper[i] for i in range(len(psd))}

for i in range(L+1):

ori[i]=trans[ori[i]]

   

print("Case #{}: ".format(t)+"".join(ori))

測試用例

4

103 31

217 1891 4819 2291 2987 3811 1739 2491 4717 445 65 1079 8383 5353 901 187 649 1003 697 3239 7663 291 123 779 1007 3551 1943 2117 1679 989 3053

10000 33

3892729 3892729 3892729 3892729 3892729 3892729 3892729 3892729 175597 18779 50429 375469 1651121 2102 3722 2376497 611683 489059 2328901 3150061 829981 421301 76409 38477 291931 730241 959821 1664197 3057407 4267589 4729181 5335543 4023959

10000 28

175597 175597 175597 175597 416303 50429 375469 1651121 2102 3722 2376497 611683 489059 2328901 3150061 829981 421301 76409 38477 291931 730241 959821 1664197 3057407 4267589 4729181 5335543 4023959

10000 29

175597 175597 175597 175597 175597 18779 50429 375469 1651121 2102 3722 2376497 611683 489059 2328901 3150061 829981 421301 76409 38477 291931 730241 959821 1664197 3057407 4267589 4729181 5335543 4023959

Case #1: CJQUIZKNOWBEVYOFDPFLUXALGORITHMS

Case #2: UUUUUUUUUBDERMATOGLYPHICFJKNQVWXZS

Case #3: UBUBUDERMATOGLYPHICFJKNQVWXZS

Case #4: UBUBUBDERMATOGLYPHICFJKNQVWXZS

相關文章
相關標籤/搜索