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
3823 - A - Flipped Cards
(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 == Pentru primul exemplu : putem transforma tot stringul in valori de 1 in 2 operatii, prima operatie la pozitia 2 si a doua la pozitia 5. Pentru al doilea exemplu : niste exemple de secvente care contin doar valori de 1 si sunt formate prin 4 operatii ar avea capetele: {1,6}, {2,6}, {1,9} ..... <br> == Exemplul 2 == ; <br> == Rezolvare == <syntaxhighlight lang="python" line> def max_length_of_sequence(N, K, cards): max_len = 0 count_zeroes = 0 left, right = 0, 0 while right < N: if cards[right] == '0': count_zeroes += 1 while count_zeroes > K: if cards[left] == '0': count_zeroes -= 1 left += 1 max_len = max(max_len, right - left + 1) right += 1 return max_len def count_sequences(N, K, cards): count = 0 count_zeroes = 0 left, right = 0, 0 while right < N: if cards[right] == '0': count_zeroes += 1 while count_zeroes > K: if cards[left] == '0': count_zeroes -= 1 left += 1 if count_zeroes == K: count += N - right right += 1 return count def solve_problem(C, N, K, cards): if C == 1: return max_length_of_sequence(N, K, cards) elif C == 2: return count_sequences(N, K, cards) def read_input(file_name): with open(file_name, 'r') as file: line = file.readline().strip().split() C, N, K = map(int, line) cards = file.readline().strip() return C, N, K, cards def write_output(file_name, result): with open(file_name, 'w') as file: file.write(str(result)) def main(): C, N, K, cards = read_input("flipc.in") result = solve_problem(C, N, K, cards) write_output("flipc.out", result) 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