Quantcast
Channel: SPOJ Discussion board - Latest posts
Viewing all 22527 articles
Browse latest View live

[AL_18_08] Mnożenie przez 11

$
0
0

Ja napisałem taki kod w C.

https://ideone.com/5s58X3

Ku mojemu rozczarowaniu musi być C++ :stuck_out_tongue:

Czy ktoś podpowie jak zmusić C++ do akceptowania trójznaków?
thx


[AL_18_08] Mnożenie przez 11

$
0
0

po co ci trójznaki ? (a to naprawdę najmniejszy kłopot)

bo poza tym nie spełniasz następujących warunków:

  1. zabroniona jest spacja
  2. zabronione są między innymi znaki: ; ’ "
  3. zabroniona jest kombinacja znaków: cl
  4. cały program musi się zmieścić w 2 liniach

Pomiar czasu wykonania programu

$
0
0

Jeżeli napiszesz tutorial lub poradnik, to jaK Najbardziej, możesz go tam umieścić. Lub jeśli maSZ konkretrne pytanie do jakiegoś wątku w tamtym dziale to możesz się tam dokleić. Jeżeli jednak pytasz, rozpoczynając nowy wątek, to raczej nie. Moim zdaniem odpowiednim jest dział PDSTPROG.

Sorry, to był taki skrót myślowy. Właśnie to miałem na myśli. Jak chcesz to zrobić [mierzyć czas …], gdy wyjdzie ci zero?

To było do podpowiadającego:

PALIN - The Next Palindrome

$
0
0

#PALIN - The Next Palindrome
t=int(input())
for t in range(t):

def palindrome(num , n):
    mid=int(n/2)
    ls=False
    i=mid-1
    j=mid+1 if (n%2) else mid
    while(i>=0 and num[i]==num[j]):
        i-=1
        j+=1
    if(i<0 or num[i]<num[j]):
        ls=True
    while(i>=0):
        num[j]=num[i]
        j+=1
        i-=1
    if(ls==True):
        carry=1
        i=mid-1
        if(n%2==1):
            num[mid]+=carry
            carry=int(num[mid]/10)
            num[mid]%=10
            j=mid+1
        else:
            j=mid

        while(i>=0):

            num[i]+=carry
            carry=int(num[i]/10)
            num[i]%=10
            num[j]=num[i]
            j+=1
            i-=1

def nextPalindrome(num,n):

    if (nines(num,n) ==True):
        print("1")
        for i in range(1,n):
            print("0")
        print("1")

    else:
        palindrome(num,n)
        printArray(num,n)

def nines(num,n):
    for i in range(n):
        if(num[i]!=9):
            return 0
    return 1
def printArray(arr,n):

    for i in range(0,n):
        print(int(arr[i]),end="")
    print()

a=int(input())
num=list(map(int,str(a)))
n=len(num)
nextPalindrome(num,n)

“”“anyone can explain why TLE”""
with regards
thank you

Spoj abcdef

[AL_18_08] Mnożenie przez 11

PALIN - The Next Palindrome

$
0
0

Did you test it with a number with 1000000 digits? That might give you an idea why it TLEs.

Cmpls wa

$
0
0

Try this test case

1
5 10
1 1 2 2 2

Expected answer

6 21 57 127 247 436 716 1112 1652 2367

To share code in IDEONE, make sure it’s set to Public or Secret, then paste the URL here.


[AL_18_08] Mnożenie przez 11

$
0
0

Dzięki za podpowiedź. Tymczasem wracam do działu “Łatwe” :stuck_out_tongue:

Prime1

$
0
0

What problem do you get?

Did you try this?

With many languages, the indentation is just an aid to reading. With Python of course, it’s far more than that. You really need to preserve the indentation when pasting in Python code, so use the preformatted text tags - the </> button .

Pomiar czasu wykonania programu

$
0
0

Spoko zero już nie wychodzi odkąd zmieniłem int na float :slight_smile:

Jak chcę mierzyć? -> Pomysł mam taki: umieszczam odpowiednio powyższy kod do programu umieszczonego na ideone. Robię kilka pomiarów dla danego wejścia i wyciągam średnią. Może zrobię jakąś statystykę z otrzymanych wartości żeby zobaczyć czy zmienność pomiaru nie jest zbyt duża.

833-BINOMS-Dwumiany

$
0
0

Cześć mam podobny problem co w tym temacie, wszystkie przykładowe wyniki mi wychodzą i myślę że nie przekraczam zakresu zmiennych, jednak sędzie mi odrzuca moje rozwiązanie, przy tworzeniu skorzystałem ze wzoru na dwumian Newtona oto kod: https://ideone.com/T57BNy

Handle an interger number of order 10^37

Prime1

$
0
0

import collections
cases = int(input())
for case in range(1, cases + 1):
a ,b = map(int, input().split())
composites = collections.defaultdict(list)

for i in range(2, b + 1):

if i in composites:
  for prime in composites[i]:
    composites[prime + i].append(prime)
  del composites[i]

else:
  if i >= a:
    print(i)
  composites[i * i] = [i]

print()
#my bad for the indentation error
#its getting TLE and i’m out of ideas to make this running
#with regards
#Thank you for the help

PALIN - The Next Palindrome

$
0
0

sorry I didn’t get you
can you elaborate .


LINESEG - Intersection

$
0
0

1
-10 3 0 3
1 3 10 3

btw, did you consider storing the result of the czy function instead of calling it three times?

PALIN - The Next Palindrome

$
0
0

Use Notepad or similar.

Create a line containing the digits 1234567890 - it’s 10 digits long
Copy it, and paste it nine times - it’s now 100 digits
Copy it, and paste it nine times - 1000 digits
Copy it, and paste it nine times - 10000 digits
Copy it, and paste it nine times - 100000 digits
Copy it, and paste it nine times - 1000000 digits

You now have an integer with 1000000 digits. Pass this to your PALIN code, and see how long it takes to give an answer.

Prime1

$
0
0

That’s why I suggested you try this. This question has been asked and answered many times, and looking through those previous posts will give you some ideas.

AL_18_01 - Iloczyn Cyfr

PALIN - The Next Palindrome

Viewing all 22527 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>