<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2896_-_binar1</id>
	<title>2896 - binar1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2896_-_binar1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2896_-_binar1&amp;action=history"/>
	<updated>2026-06-17T09:34:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=2896_-_binar1&amp;diff=9056&amp;oldid=prev</id>
		<title>Miawinator: Pagină nouă: Pentru a converti un număr din zecimal în binar îl vom împărți la &lt;code&gt;2&lt;/code&gt; în mod repetat, până ce obținem câtul zero. Apoi vom colecta resturile obținute de la ultimul către primul. Aceste resturi sunt cifrele din reprezentarea binară a numărului dat, de la stânga la dreapta. De exemplu, &lt;code&gt;13(10)&lt;/code&gt; &lt;code&gt;= 1101(2)&lt;/code&gt;.  = Cerința = Scrieți un program care, pentru un șir dat de n numere naturale, rezolvă următoarele cerințe:  1) Determi...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2896_-_binar1&amp;diff=9056&amp;oldid=prev"/>
		<updated>2024-01-05T02:13:48Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Pentru a converti un număr din zecimal în binar îl vom împărți la &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; în mod repetat, până ce obținem câtul zero. Apoi vom colecta resturile obținute de la ultimul către primul. Aceste resturi sunt cifrele din reprezentarea binară a numărului dat, de la stânga la dreapta. De exemplu, &amp;lt;code&amp;gt;13(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 1101(2)&amp;lt;/code&amp;gt;.  = Cerința = Scrieți un program care, pentru un șir dat de n numere naturale, rezolvă următoarele cerințe:  1) Determi...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Pentru a converti un număr din zecimal în binar îl vom împărți la &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; în mod repetat, până ce obținem câtul zero. Apoi vom colecta resturile obținute de la ultimul către primul. Aceste resturi sunt cifrele din reprezentarea binară a numărului dat, de la stânga la dreapta. De exemplu, &amp;lt;code&amp;gt;13(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 1101(2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Scrieți un program care, pentru un șir dat de n numere naturale, rezolvă următoarele cerințe:&lt;br /&gt;
&lt;br /&gt;
1) Determină cel mai mare dintre cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere date ce are număr maxim de valori de &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; în reprezentarea binară.&lt;br /&gt;
&lt;br /&gt;
2) Determină cea mai lungă secvență de numere care au număr egal de valori de &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; în reprezentarea binară. Dacă sunt mai multe astfel de secvențe de lungime maximă, se va alege cea mai din stânga. O secvență este un subșir de numere care apar pe poziții consecutive în șirul inițial.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;input.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt; reprezentând cerința (&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; sau &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;), pe a doua linie numărul natural &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe a treia linie &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale separate prin câte un spațiu.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Dacă &amp;lt;code&amp;gt;C = 1&amp;lt;/code&amp;gt;, atunci pe prima linie a fișierului de ieșire &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; se va scrie numărul ce reprezintă răspunsul la cerința &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;. Dacă &amp;lt;code&amp;gt;C = 2&amp;lt;/code&amp;gt;, atunci pe prima linie a fișierului de ieșire &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; se vor scrie, separate printr-un spațiu, lungimea maximă a secvenței determinate și poziția primului termen din secvență (se consideră că primul număr din cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere date se găsește pe poziția &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 1.000.000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
7&lt;br /&gt;
&lt;br /&gt;
16 12 3 5 14 13 11&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
14&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;16(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 10000(2)&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;12(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 1100(2)&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;3(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 11(2)&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;5(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 101(2)&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;14(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 1110(2)&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;13(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 1101(2)&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;11(10)&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= 1011(2)&amp;lt;/code&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
Cel mai mare număr de valori de &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; dintr-o reprezentare binară este &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;; cel mai mare număr ce are &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt; de &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; în reprezentarea binară este &amp;lt;code&amp;gt;14&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
7&lt;br /&gt;
&lt;br /&gt;
16 12 3 5 14 13 11&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
3 2&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Sunt două secvențe de lungime maximă de numere care au număr egal de valori de &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; în reprezentarea binară: &amp;lt;code&amp;gt;12 3 5&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;14 13 11&amp;lt;/code&amp;gt;. O vom alege pe cea mai din stânga, care are lungimea &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt; și începe la poziția &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 3 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
99999999999999&lt;br /&gt;
&lt;br /&gt;
16 12 3 5 14 13 11&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Input-ul nu convine conditiilor&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
NM = 1000001&lt;br /&gt;
&lt;br /&gt;
def verificare(n):&lt;br /&gt;
    if not(1&amp;lt;=n&amp;lt;=1000000):&lt;br /&gt;
        print(&amp;quot;Input-ul nu convine conditiilor&amp;quot;)&lt;br /&gt;
        exit()&lt;br /&gt;
&lt;br /&gt;
def count_set_bits(num):&lt;br /&gt;
    count = 0&lt;br /&gt;
    while num:&lt;br /&gt;
        count += num &amp;amp; 1&lt;br /&gt;
        num &amp;gt;&amp;gt;= 1&lt;br /&gt;
    return count&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;) as fin, open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as fout:&lt;br /&gt;
    c = int(fin.readline())&lt;br /&gt;
    n = int(fin.readline())&lt;br /&gt;
&lt;br /&gt;
    verificare(n)&lt;br /&gt;
&lt;br /&gt;
    l=list(map(int, fin.readline().split()))&lt;br /&gt;
&lt;br /&gt;
    a = [0] * (n + 1)&lt;br /&gt;
    &lt;br /&gt;
    xmax = 0&lt;br /&gt;
    nr1max = 0&lt;br /&gt;
    &lt;br /&gt;
    for i in range(1, n + 1):&lt;br /&gt;
        x = l[i-1]&lt;br /&gt;
        aux = x&lt;br /&gt;
        nr1 = 0&lt;br /&gt;
        &lt;br /&gt;
        while aux &amp;gt; 0:&lt;br /&gt;
            nr1 += 1&lt;br /&gt;
            aux = aux &amp;amp; (aux - 1)&lt;br /&gt;
        &lt;br /&gt;
        if nr1 &amp;gt; nr1max or (nr1 == nr1max and x &amp;gt; xmax):&lt;br /&gt;
            nr1max = nr1&lt;br /&gt;
            xmax = x&lt;br /&gt;
        &lt;br /&gt;
        a[i] = nr1&lt;br /&gt;
    &lt;br /&gt;
    if c == 1:&lt;br /&gt;
        # cerinta 1&lt;br /&gt;
        fout.write(str(xmax))&lt;br /&gt;
    else:&lt;br /&gt;
        # cerinta 2&lt;br /&gt;
        lgm = 0&lt;br /&gt;
        lgc = 1&lt;br /&gt;
        pc = 1&lt;br /&gt;
        &lt;br /&gt;
        for i in range(2, n + 1):&lt;br /&gt;
            if a[i] == a[i - 1]:&lt;br /&gt;
                lgc += 1&lt;br /&gt;
            else:&lt;br /&gt;
                if lgc &amp;gt; lgm:&lt;br /&gt;
                    lgm = lgc&lt;br /&gt;
                    pm = pc&lt;br /&gt;
                lgc = 1&lt;br /&gt;
                pc = i&lt;br /&gt;
        &lt;br /&gt;
        if lgc &amp;gt; lgm:&lt;br /&gt;
            lgm = lgc&lt;br /&gt;
            pm = pc&lt;br /&gt;
        &lt;br /&gt;
        fout.write(f&amp;quot;{lgm} {pm}&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Miawinator</name></author>
	</entry>
</feed>