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
1033 - Elicop
(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 = Elicopterele <code>2</code> şi <code>4</code> nu afectează niciun pătrăţel de gazon. Elicopterele <code>1</code> şi <code>3</code> afectează fiecare mai mult de jumătate din numărul pătrăţelelor asociate triunghiurilor dreptunghice şi deci aterizează greşit. Elicopterul <code>1</code> face umbră la <code>6</code> pătrăţele, din care afectate sunt <code>4</code>. Elicopterul <code>3</code> face umbră la <code>3</code> pătrăţele, din care afectate sunt două. <syntaxhighlight lang="python" line="1"> def citire_date(nume_fisier): with open(nume_fisier, 'r') as f: m, n = map(int, f.readline().split()) a = [list(map(int, f.readline().split())) for _ in range(m)] k = int(f.readline()) elicoptere = [] for _ in range(k): lin1, col1, lin2, col2, poz = map(int, f.readline().split()) elicoptere.append((lin1, col1, lin2, col2, poz)) return m, n, a, k, elicoptere def triunghi_umbre(m, n, a, lin1, col1, lin2, col2, poz): umbite = 0 total = 0 if poz == 1: for i in range(lin1, lin2+1): for j in range(col1, col2+1): total += 1 if a[i-1][j-1] == 0: umbite += 1 else: for i in range(lin2, lin1+1): for j in range(col1, col2+1): total += 1 if a[i-1][j-1] == 0: umbite += 1 return umbite, total def verifica_aterizari(m, n, a, k, elicoptere): n1 = 0 elicoptere_gresite = [] for idx, (lin1, col1, lin2, col2, poz) in enumerate(elicoptere, start=1): umbite, total = triunghi_umbre(m, n, a, lin1, col1, lin2, col2, poz) if umbite == 0: n1 += 1 elif umbite > total / 2: elicoptere_gresite.append(idx) return n1, elicoptere_gresite def scrie_rezultate(nume_fisier, n1, elicoptere_gresite): with open(nume_fisier, 'w') as f: f.write(f"{n1}\n") f.write(f"{len(elicoptere_gresite)} {' '.join(map(str, elicoptere_gresite))}\n") # Main function def main(): m, n, a, k, elicoptere = citire_date('date.in') n1, elicoptere_gresite = verifica_aterizari(m, n, a, k, elicoptere) scrie_rezultate('date.out', n1, elicoptere_gresite) 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