<?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=3574_-_Perspic</id>
	<title>3574 - Perspic - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3574_-_Perspic"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3574_-_Perspic&amp;action=history"/>
	<updated>2026-05-01T14:21:38Z</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=3574_-_Perspic&amp;diff=10217&amp;oldid=prev</id>
		<title>RaulOtet: Pagină nouă: Se consideră o matrice pătratică cu &lt;code&gt;N&lt;/code&gt; linii şi &lt;code&gt;N&lt;/code&gt; coloane ce conţine toate numerele naturale de la &lt;code&gt;1&lt;/code&gt; la &lt;code&gt;N*N&lt;/code&gt;.  Asupra matricei se definesc trei tipuri de operaţii codificate astfel:  * &lt;code&gt;C i j&lt;/code&gt; – interschimbarea coloanelor &lt;code&gt;i&lt;/code&gt; şi &lt;code&gt;j&lt;/code&gt; ale matricei * &lt;code&gt;R i j&lt;/code&gt; – interschimbarea liniilor &lt;code&gt;i&lt;/code&gt; şi &lt;code&gt;j&lt;/code&gt; ale matricei * &lt;code&gt;E i j x y&lt;/code&gt; – interschimbarea...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3574_-_Perspic&amp;diff=10217&amp;oldid=prev"/>
		<updated>2024-08-08T06:10:21Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Se consideră o matrice pătratică cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; linii şi &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; coloane ce conţine toate numerele naturale de la &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;N*N&amp;lt;/code&amp;gt;.  Asupra matricei se definesc trei tipuri de operaţii codificate astfel:  * &amp;lt;code&amp;gt;C i j&amp;lt;/code&amp;gt; – interschimbarea coloanelor &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt; ale matricei * &amp;lt;code&amp;gt;R i j&amp;lt;/code&amp;gt; – interschimbarea liniilor &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt; ale matricei * &amp;lt;code&amp;gt;E i j x y&amp;lt;/code&amp;gt; – interschimbarea...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Se consideră o matrice pătratică cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; linii şi &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; coloane ce conţine toate numerele naturale de la &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;N*N&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Asupra matricei se definesc trei tipuri de operaţii codificate astfel:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;C i j&amp;lt;/code&amp;gt; – interschimbarea coloanelor &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt; ale matricei&lt;br /&gt;
* &amp;lt;code&amp;gt;R i j&amp;lt;/code&amp;gt; – interschimbarea liniilor &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt; ale matricei&lt;br /&gt;
* &amp;lt;code&amp;gt;E i j x y&amp;lt;/code&amp;gt; – interschimbarea elementului de pe linia &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; şi coloana &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt; cu elementul de pe linia &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; şi coloana &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Asupra matricei se efectuează un set de &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; astfel de operaţii.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Se cere să se determine numărul minim de aplicări complete ale acestui set de operaţii după care se ajunge din nou în starea iniţială. În cadrul setului operaţiile se efectuează mereu în aceeaşi ordine şi nu se poate sări peste o operaţie. Deoarece numărul acesta poate fi foarte mare se cere restul împărţirii sale la &amp;lt;code&amp;gt;13007&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;perspic.in&amp;lt;/code&amp;gt; conţine pe prima linie numerele naturale &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt;, separate printr-un spaţiu, reprezentând dimensiunea matricei şi respectiv numărul de operaţii dintr-un set. Pe următoarele &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; linii se descriu operaţiile setului.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;perspic.out&amp;lt;/code&amp;gt; va conţine restul împărţirii la &amp;lt;code&amp;gt;13007&amp;lt;/code&amp;gt; al numărului minim determinat.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ N ≤ 100&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ M ≤ 10.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* Pentru &amp;lt;code&amp;gt;60%&amp;lt;/code&amp;gt; din teste numărul minim de aplicări ale setului de operaţii necesare va fi mai mic ca &amp;lt;code&amp;gt;2.000.000.000&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;perspic.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 2 2&lt;br /&gt;
 C 1 2&lt;br /&gt;
 R 1 2&lt;br /&gt;
&amp;lt;code&amp;gt;perspic.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 2&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def gcd(a, b):&lt;br /&gt;
    while b:&lt;br /&gt;
        a, b = b, a % b&lt;br /&gt;
    return a&lt;br /&gt;
&lt;br /&gt;
def lcm(a, b):&lt;br /&gt;
    return a * b // gcd(a, b)&lt;br /&gt;
&lt;br /&gt;
def find_cycles(permutation):&lt;br /&gt;
    visited = [False] * len(permutation)&lt;br /&gt;
    cycles = []&lt;br /&gt;
    for i in range(len(permutation)):&lt;br /&gt;
        if not visited[i]:&lt;br /&gt;
            cycle_length = 0&lt;br /&gt;
            x = i&lt;br /&gt;
            while not visited[x]:&lt;br /&gt;
                visited[x] = True&lt;br /&gt;
                x = permutation[x]&lt;br /&gt;
                cycle_length += 1&lt;br /&gt;
            cycles.append(cycle_length)&lt;br /&gt;
    return cycles&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    import sys&lt;br /&gt;
    input = sys.stdin.read&lt;br /&gt;
    data = input().strip().split()&lt;br /&gt;
    &lt;br /&gt;
    idx = 0&lt;br /&gt;
    N = int(data[idx])&lt;br /&gt;
    idx += 1&lt;br /&gt;
    M = int(data[idx])&lt;br /&gt;
    idx += 1&lt;br /&gt;
    &lt;br /&gt;
    permutation = list(range(N * N))&lt;br /&gt;
    &lt;br /&gt;
    for _ in range(M):&lt;br /&gt;
        operation = data[idx]&lt;br /&gt;
        if operation == &amp;#039;C&amp;#039;:&lt;br /&gt;
            i = int(data[idx + 1]) - 1&lt;br /&gt;
            j = int(data[idx + 2]) - 1&lt;br /&gt;
            idx += 3&lt;br /&gt;
            for row in range(N):&lt;br /&gt;
                permutation[row * N + i], permutation[row * N + j] = permutation[row * N + j], permutation[row * N + i]&lt;br /&gt;
        elif operation == &amp;#039;R&amp;#039;:&lt;br /&gt;
            i = int(data[idx + 1]) - 1&lt;br /&gt;
            j = int(data[idx + 2]) - 1&lt;br /&gt;
            idx += 3&lt;br /&gt;
            for col in range(N):&lt;br /&gt;
                permutation[i * N + col], permutation[j * N + col] = permutation[j * N + col], permutation[i * N + col]&lt;br /&gt;
        elif operation == &amp;#039;E&amp;#039;:&lt;br /&gt;
            i = int(data[idx + 1]) - 1&lt;br /&gt;
            j = int(data[idx + 2]) - 1&lt;br /&gt;
            x = int(data[idx + 3]) - 1&lt;br /&gt;
            y = int(data[idx + 4]) - 1&lt;br /&gt;
            idx += 5&lt;br /&gt;
            permutation[i * N + j], permutation[x * N + y] = permutation[x * N + y], permutation[i * N + j]&lt;br /&gt;
    &lt;br /&gt;
    cycles = find_cycles(permutation)&lt;br /&gt;
    result = 1&lt;br /&gt;
    for cycle_length in cycles:&lt;br /&gt;
        result = lcm(result, cycle_length)&lt;br /&gt;
    &lt;br /&gt;
    print(result % 13007)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>RaulOtet</name></author>
	</entry>
</feed>