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
1115 - Avarcolaci
(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 = # Dacă împărțim în grupuri vârcolacii asociați celor <code>4</code> săteni obținem <code>(1, 3) (4, 4)</code> și nu avem un vârcolac atât în primul grup, cât și în al doilea. # Vârcolacul <code>1</code> bântuie satul. # Vârcolacul <code>4</code> bântuie satul – nu putem împărți sătenii în două grupuri astfel încât <code>4</code> să nu fie în niciunul dintre ele. == Exemplu 2: == <code>avarcolaciIN.txt</code> 16 2 1 4 3 4 1 1 1 3 4 1 4 4 4 4 <code>avarcolaciOUT.txt</code> Datele nu corespund restrictiilor impuse <br> == Rezolvare == <syntaxhighlight lang="python" line="1"> def verifica_restrictii(nr_teste, n, el): TMAX = 15 NMAX = 500000 EL_MAX = int(1e9) if not (1 <= nr_teste <= TMAX): return False if not (1 <= n <= NMAX): return False if not (0 <= el <= EL_MAX): return False return True def main(): with open("avarcolaciIN.txt", "rt") as f_in, open("avarcolaciOUt.txt", "wt") as f_out: nr_teste = int(f_in.readline().strip()) if not verifica_restrictii(nr_teste, 1, 0): f_out.write("Datele nu corespund restrictiilor impuse\n") return potential = [0] * (nr_teste + 1) for test in range(1, nr_teste + 1): n = int(f_in.readline().strip()) if not verifica_restrictii(1, n, 0): f_out.write("Datele nu corespund restrictiilor impuse\n") return maj, cnt = -1, 0 elements = list(map(int, f_in.readline().split())) if not all(verifica_restrictii(1, 1, el) for el in elements): f_out.write("Datele nu corespund restrictiilor impuse\n") return for el in elements: if maj == -1: maj = el cnt = 1 else: if el == maj: cnt += 1 else: cnt -= 1 if cnt == 0: maj = el cnt = 1 potential[test] = maj with open("avarcolaciIN.txt", "rt") as f_in: nr_teste = int(f_in.readline().strip()) for test in range(1, nr_teste + 1): n = int(f_in.readline().strip()) elements = list(map(int, f_in.readline().split())) cnt = 0 for x in elements: if x == potential[test]: cnt += 1 with open("avarcolaciOUt.txt", "a") as f_out: if cnt > n: f_out.write(f"{potential[test]}\n") else: f_out.write("Mozart\n") 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