Translate

Views

Monday, September 9, 2024

Solution UVA: 11428 - Cubes

 

 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss11428 - Cubes AcceptedPython0.0200.00029291 mins ago

Suggest:

61^3 - 60^3 > 10000 so x_max <= 60


r = {}
for x in range(1, 61):
    for y in range(1, x):

        if x**3-y**3 in r:
       
            u, v = r[x**3-y**3]
            if (v > y):
                r[x**3-y**3] = (x,y)
       
        else:
           
            r[x**3-y**3] = (x,y)
while True:
    n = int(input())
    if n == 0:
        break
    if n not in r:
        print('No solution')
    else:
        x, y = r[n]
        print(f"{x} {y}")

Friday, September 6, 2024

Solution UVA: 10878 - Decode the tape

 

 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10878 - Decode the tape AcceptedPython0.1800.00056151 mins ago

Suggest:

- In the problems decode, i think we should make doing step:

1/ Look overview and get information easy know like

+ input we have 8 char / line -> now we know need use bit
+ number of line = nuimber of char in string -> now we know every line is a present a char of output

2/ Thinking top down problem 

+ A -> 65 -> 01000001 -> |_o___.__o|


_ = input()
while True:
    s = input()
    if s == '___________':
        break

    k = 0
    n = 0
   
    for i in range(len(s)-1, 0, -1):
       
        if s[i] == 'o':
            n += 1 << k
            k += 1
       
        if s[i] == ' ':
            k += 1
           
    print(chr(n), end='')