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
0599 - Covoare
(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!
= Exemplu: = <code>covoare.in</code> 5 6 8 3 2 2 1 1 1 2 3 2 1 1 4 4 2 3 2 2 1 2 1 1 2 1 3 <code>covoare.out</code> 2 2 2 1 2 2 2 2 2 4 2 2 3 3 3 3 2 2 3 3 3 3 1 1 1 1 3 3 1 1 == Rezolvare == <syntaxhighlight lang="python3"> def read_input(n, m, p): carpets = [] for _ in range(p): a, b, c = map(int, input().split()) carpets.append((a, b, c)) return carpets def is_valid_placement(carpets, n, m): used_area = [[False for _ in range(m)] for _ in range(n)] for a, b, _ in carpets: for i in range(n - a + 1): for j in range(m - b + 1): if used_area[i][j]: return False for x in range(a): for y in range(b): used_area[i + x][j + y] = True return True def place_carpets(carpets, n, m): """Arranges the carpets on the floor.""" floor = [[0 for _ in range(m)] for _ in range(n)] for a, b, c in carpets: for i in range(n - a + 1): for j in range(m - b + 1): if not used_area[i][j]: for x in range(a): for y in range(b): floor[i + x][j + y] = c used_area[i + x][j + y] = True break return floor def print_floor(floor, n, m): for i in range(n): for j in range(m): print(floor[i][j], end=" ") print() def main(): n, m, p = map(int, input().split()) carpets = read_input(n, m, p) if not is_valid_placement(carpets, n, m): print("IMPOSIBIL") return floor = place_carpets(carpets, n, m) print_floor(floor, n, m) 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