Translate

Views

Friday, July 28, 2023

Solution UVA: 10176 - Ocean Deep! Make it shallow!!


 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10176 - Ocean Deep! - Make it shallow!! AcceptedPython0.1500.00026777 mins ago

Suggest:

Method 1:

- Easy if you know to use python, because python can calc big number


Method 2:
- Else if you want to use C++ to solve, you can use this method:

Input: 1010101#

Explanation:

Read ch = '1', ans = 1.

Read ch = '0', ans = 1 * 2 + 0 = 2.

Read ch = '1', ans = 2 * 2 + 1 = 5.

Read ch = '0', ans = 5 * 2 + 0 = 10.

Read ch = '1', ans = 10 * 2 + 1 = 21.

Read ch = '0', ans = 21 * 2 + 0 = 42.

Read ch = '1', ans = 42 * 2 + 1 = 85.

Read ch = '#', end of the loop.

Note % after reads to avoid big number

Output: NO


Code python use method 1

s=""
while True:
    try:
        s+= input()
    except:
        break
    binary= s.split('#')[0]
    if (len(binary) != len(s)):
        s=""
        print("NO") if int(binary,2)%131071 else print("YES")

No comments: