Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1123 - Iepurasi
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Explicație = Se aplică o singură operaţie <code>TAP</code> pe iepuraşul cu numărul de ordine <code>5</code>. Cartonaşul neîntors are numărul de ordine <code>14</code> (<code>999</code>). == Încărcare soluție == === Lipește codul aici === <syntaxhighlight lang="python" line="1"> import sys f = open("iepurasi.txtin", "r") g = open("iepurasi.txtout", "w") toate = [0] * 200001 ncurent = 0 N = 0 a = [0] * 10001 dim_sir = 0 TAP = 0 nr1 = 0 nr2 = 0 viz = [False] * 10001 fr7 = [0] * 200001 fr8 = [0] * 200001 fr9 = [0] * 200001 def main(): global N, a, TAP, viz i = 0 j = 0 k = 0 maxi = 0 imax = 0 aux = 0 c7 = 0 c8 = 0 c9 = 0 #citire N = int(f.readline()) a = list(map(int, f.readline().split())) #sortare descrescatoare for i in range(1, N + 1): imax = i maxi = a[i] for j in range(i + 1, N + 1): if a[j] > maxi: maxi = a[j] imax = j if imax != i: if a[N] != maxi: TAP += 1 #TAP pe iepurasul imax for j in range(imax, k, -1): aux = a[j] a[j] = a[k] a[k] = aux viz[j] = True viz[k] = True #TAP pe iepurasul i if a[i] != maxi: TAP += 1 for j in range(i, k, -1): aux = a[j] a[j] = a[k] a[k] = aux viz[j] = True viz[k] = True #det cartonas minim/maxim if viz[1]: k = a[1] else: i = 1 while not viz[i] and i <= N: i += 1 k = a[i - 1] #constructie sir de numere cu cifrele 7,8,9 pana la numarul de pe pozitia k fr7[1] = 1 fr8[2] = 1 fr9[3] = 1 toate[1] = 7 toate[2] = 8 toate[3] = 9 dim_sir = 0 nr1 = 1 nr2 = 3 while dim_sir < k: c7 = fr7[nr1] c8 = fr8[nr1] c9 = fr9[nr1] ncurent = toate[nr1] nr1 += 1 nr2 -= 1 if c7 <= c8 and c8 <= c9: dim_sir += 1 fr7[nr1 + nr2] = c7 + 1 fr8[nr1 + nr2] = c8 fr9[nr1 + nr2] = c9 toate[nr1 + nr2] = 10 * ncurent + 7 nr2 += 1 fr7[nr1 + nr2] = c7 fr8[nr1 + nr2] = c8 + 1 fr9[nr1 + nr2] = c9 toate[nr1 + nr2] = 10 * ncurent + 8 nr2 += 1 fr7[nr1 + nr2] = c7 fr8[nr1 + nr2] = c8 fr9[nr1 + nr2] = c9 + 1 toate[nr1 + nr2] = 10 * ncurent + 9 nr2 += 1 #afisare g.write(str(TAP) + "\n" + str(ncurent) + "\n") f.close() g.close() sys.exit(0) if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width