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
2445 - Turnuri 1
(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!
= Exemplul 1: = <code>turnuri1.in</code> 1 6 18 a 13 g 15 a 10 a 8 g 2 a <code>turnuri1.out</code> 3 31 == Încărcare soluție == === Lipește codul aici === <syntaxhighlight lang="python" line="1"> # Framework and technology stack: C++ with standard library import sys from typing import List fin = open("turnuri1.in", "r") fout = open("turnuri1.out", "w") C: int n: int n1: int n2: int nr_turnuri: int max_turn: int v1: List[int] = [0] * 10003 v2: List[int] = [0] * 10003 v3: int def citire() -> None: global C, n, n1, n2, nr_turnuri, max_turn l1: int l2: int h_turn: int cul1: str cul2: str data = fin.readline().split() C = int(data[0]) n = int(data[1]) data = fin.readline().split() l1 = int(data[0]) cul1 = data[1] nr_turnuri = 1 h_turn = l1 if cul1 == 'g': n1 += 1 v1[n1] = l1 else: n2 += 1 v2[n2] = l1 for i in range(n - 1): data = fin.readline().split() l2 = int(data[0]) cul2 = data[1] if l2 < l1 and cul2 != cul1: h_turn += l2 else: nr_turnuri += 1 h_turn = l2 if h_turn > max_turn: max_turn = h_turn l1 = l2 cul1 = cul2 def cmp(a: int, b: int) -> bool: return a > b def main() -> None: global n1, n2, v1, v2 i: int j: int k: int p: int citire() if C == 1: fout.write(str(nr_turnuri) + ' ' + str(max_turn) + '\n') else: v1 = sorted(v1[1:n1 + 1], reverse=True) v2 = sorted(v2[1:n2 + 1], reverse=True) v1.append(500003) v2.append(500002) i = 1 j = 1 k = 0 if v1[i] > v2[j]: k += 1 v3 = v1[i] i += 1 p = 1 else: k += 1 v3 = v2[j] j += 1 p = -1 while i <= n1 and j <= n2: if p == 1: while j <= n2 and v2[j] >= v3: j += 1 if j <= n2: k += 1 v3 = v2[j] j += 1 p = -p else: while i <= n1 and v1[i] >= v3: i += 1 if i <= n1: k += 1 v3 = v1[i] i += 1 p = -p if p == -1: for i in range(i, n1 + 1): if v1[i] < v3: k += 1 v3 = v1[i] break if p == 1: for j in range(j, n2 + 1): if v2[j] < v3: k += 1 v3 = v2[j] break fout.write(str(k) + '\n') fin.close() fout.close() 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