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
3724 - Dreptunghi 2
(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 2: = Intrare 2 H3V2**H2V3**V2*V3** Ieșire 6 6 === Explicație === Cel mai mic dreptunghi pentru care codul este valid are <code>6</code> linii și <code>6</code> coloane. == Rezolvare == <syntaxhighlight lang="python" line="1"> MOD = 1000000007 class RetType: def __init__(self, type, offset, cnt, s1, s2): self.type = type self.offset = offset self.cnt = cnt self.s1 = s1 self.s2 = s2 sir = "" din = [0] * 355 pos = 0 cntDrept = 0 cntStr = 1 lenH = 0 lenV = 0 def parseInt(): global pos s = 0 while pos < len(sir) and '0' <= sir[pos] <= '9': s = s * 10 + int(sir[pos]) - int('0') pos += 1 return s def solve(h, v): global pos, cntDrept, cntStr, lenH, lenV, din currType = sir[pos] pos += 1 if currType == '*': cntDrept += 1 lenH = max(lenH, h + 1) lenV = max(lenV, v + 1) return RetType('*', 0, 0, "", "*") k = parseInt() ret = RetType(currType, k, 1, "", "") aux1 = solve(h, v) if aux1.type == currType: ret.cnt += aux1.cnt ret.s1 += aux1.s1 ret.s1 += currType ret.s1 += str(k - aux1.offset) ret.s1 += aux1.s2 else: cntStr = (1 * cntStr * din[aux1.cnt]) % MOD ret.s1 += currType ret.s1 += str(k) ret.s1 += aux1.s1 + aux1.s2 newH = h newV = v if currType == 'H': newH += k else: newV += k aux2 = solve(newH, newV) if aux2.type == currType: ret.cnt += aux2.cnt ret.offset += aux2.offset ret.s1 += aux2.s1 ret.s2 += aux2.s2 else: cntStr = (1 * cntStr * din[aux2.cnt]) % MOD ret.s2 += aux2.s1 + aux2.s2 return ret def restrictii(type, sir): if not (1 <= type <= 4): print("Datele nu corespund restrictiilor impuse") return False if not (0 < len(sir) < 350): print("Datele nu corespund restrictiilor impuse") return False return True def main(): global pos, sir, cntStr, din type = int(input()) sir = input().strip() if not restrictii(type, sir): return din[0] = din[1] = 1 for i in range(2, 351): din[i] = 0 for j in range(i): din[i] = (din[i] + 1 * din[j] * din[i - j - 1]) % MOD aux = solve(0, 0) cntStr = (1 * cntStr * din[aux.cnt]) % MOD if type == 1: print(cntDrept) elif type == 2: print(lenH, lenV) elif type == 3: print(cntStr) else: print(aux.s1 + aux.s2) 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