Ja napisałem taki kod w C.
Ku mojemu rozczarowaniu musi być C++
Czy ktoś podpowie jak zmusić C++ do akceptowania trójznaków?
thx
Ja napisałem taki kod w C.
Ku mojemu rozczarowaniu musi być C++
Czy ktoś podpowie jak zmusić C++ do akceptowania trójznaków?
thx
po co ci trójznaki ? (a to naprawdę najmniejszy kłopot)
bo poza tym nie spełniasz następujących warunków:
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
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
I’ve not solved this problem, but this link might help.
Baaardzo daleka droga przed Tobą. Proponuję zebyś najpierw się pobawił zadaniami w challegne na skracanie kodu źródłowego, np: https://pl.spoj.com/problems/SUMAN/
Podobnym zadaniem w wersji easy jest: https://pl.spoj.com/problems/BEZPRZEC/
Did you test it with a number with 1000000 digits? That might give you an idea why it TLEs.
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.
Dzięki za podpowiedź. Tymczasem wracam do działu “Łatwe”
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 .
Spoko zero już nie wychodzi odkąd zmieniłem int na float
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.
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
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
sorry I didn’t get you
can you elaborate .
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?
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.
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.
Witam,
proszę o wyjaśnienie, dlaczego cały czas otrzymuję WA.
Kod: https://ideone.com/5PT9Kg
Pomijałem również wypisywanie 0, jednak nie pomogło.
hats of for this
thank you