<?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=1221_-_PieseSah</id>
	<title>1221 - PieseSah - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1221_-_PieseSah"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1221_-_PieseSah&amp;action=history"/>
	<updated>2026-05-01T09:09:29Z</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=1221_-_PieseSah&amp;diff=10204&amp;oldid=prev</id>
		<title>RaulOtet: Pagină nouă: = Cerința = Se consideră o tablă de șah de dimensiune &lt;code&gt;n&lt;/code&gt; (alcătuită din &lt;code&gt;n&lt;/code&gt; linii si &lt;code&gt;n&lt;/code&gt; coloane), pe care se află &lt;code&gt;m&lt;/code&gt; piese de șah, fiecare putând fi: pion, rege, regină, nebun, tură sau cal). Se dau coordonatele a &lt;code&gt;t&lt;/code&gt; căsuțe de pe tablă și se cere să se verifice pentru fiecare dacă este atacată, ocupată sau neatacată de piesele care se află pe tablă .  = Date de intrare = Fișierul de intrare &lt;cod...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1221_-_PieseSah&amp;diff=10204&amp;oldid=prev"/>
		<updated>2024-07-31T05:50:41Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerința = Se consideră o tablă de șah de dimensiune &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; (alcătuită din &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii si &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; coloane), pe care se află &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; piese de șah, fiecare putând fi: pion, rege, regină, nebun, tură sau cal). Se dau coordonatele a &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; căsuțe de pe tablă și se cere să se verifice pentru fiecare dacă este atacată, ocupată sau neatacată de piesele care se află pe tablă .  = Date de intrare = Fișierul de intrare &amp;lt;cod...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Cerința =&lt;br /&gt;
Se consideră o tablă de șah de dimensiune &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; (alcătuită din &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii si &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; coloane), pe care se află &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; piese de șah, fiecare putând fi: pion, rege, regină, nebun, tură sau cal). Se dau coordonatele a &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; căsuțe de pe tablă și se cere să se verifice pentru fiecare dacă este atacată, ocupată sau neatacată de piesele care se află pe tablă .&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;piesesah.in&amp;lt;/code&amp;gt; conține pe prima linie trei numere &amp;lt;code&amp;gt;n m t&amp;lt;/code&amp;gt;. Următoarele &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; linii conțin un caracter, literă mică (reprezentând tipul piesei) urmat de două numere naturale reprezentând coordonatele piesei. Următoarele &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; linii conțin câte două numere naturale reprezentând coordonatele unei căsuțe care trebuie verificată.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;piesesah.out&amp;lt;/code&amp;gt; va conține pe &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; linii câte un singur număr natural &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; sau &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, după cum căsuța corespunzătoare este neatacată, atacată sau ocupată.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 1000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ m &amp;lt; n * n&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ t ≤ 50000&amp;lt;/code&amp;gt;&lt;br /&gt;
* Nu vor exista două piese pe aceeași poziție;&lt;br /&gt;
* Caracterele care precizează piesele de pe tablă pot fi:&lt;br /&gt;
** &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; – pion;&lt;br /&gt;
** &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt; – rege;&lt;br /&gt;
** &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; – regină;&lt;br /&gt;
** &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; – nebun;&lt;br /&gt;
** &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; – tură;&lt;br /&gt;
** &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; – cal;&lt;br /&gt;
* Piesele de pe tablă atacă astfel:&lt;br /&gt;
** regele atacă oricare dintre cele &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; căsuțe vecine pe linie, coloană sau diagonale, situate pe tablă;&lt;br /&gt;
** pionul atacă oricare dintre cele &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt; căsuțe vecine pe diagonale, situate pe tablă;&lt;br /&gt;
** calul atacă oricare dintre &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; căsuțe, situate pe tablă, în care poate ajunge sărind în &amp;lt;code&amp;gt;L&amp;lt;/code&amp;gt;;&lt;br /&gt;
** regina atacă orice căsuță de pe tablă aflată pe aceeași linie, coloană sau diagonală cu ea, dar până la întâlnirea altei piese;&lt;br /&gt;
** nebunul atacă orice căsuță de pe tablă aflată pe aceeași diagonală cu el, dar până la întâlnirea altei piese;&lt;br /&gt;
** tura atacă orice căsuță de pe tablă aflată pe aceeași linie sau coloană cu ea, dar până la întâlnirea altei piese;&lt;br /&gt;
&lt;br /&gt;
= Exemplu =&lt;br /&gt;
&amp;lt;code&amp;gt;piesesah.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 10 6 10&lt;br /&gt;
 p 1 1&lt;br /&gt;
 r 8 9&lt;br /&gt;
 q 3 2&lt;br /&gt;
 n 6 7&lt;br /&gt;
 t 2 9&lt;br /&gt;
 c 9 3&lt;br /&gt;
 1 1&lt;br /&gt;
 5 5&lt;br /&gt;
 2 3&lt;br /&gt;
 5 2&lt;br /&gt;
 9 6&lt;br /&gt;
 8 9&lt;br /&gt;
 10 10&lt;br /&gt;
 9 2&lt;br /&gt;
 2 2&lt;br /&gt;
 7 2&lt;br /&gt;
&amp;lt;code&amp;gt;piesesah.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 2&lt;br /&gt;
 0&lt;br /&gt;
 1&lt;br /&gt;
 1&lt;br /&gt;
 0&lt;br /&gt;
 2&lt;br /&gt;
 0&lt;br /&gt;
 1&lt;br /&gt;
 1&lt;br /&gt;
 1&lt;br /&gt;
&lt;br /&gt;
=== Explicație ===&lt;br /&gt;
Tabla de șah arată astfel:&lt;br /&gt;
 2 1 0 1 0 0 0 0 1 0 &lt;br /&gt;
 1 1 1 1 1 1 1 1 2 1 &lt;br /&gt;
 1 2 1 1 1 1 1 1 1 1 &lt;br /&gt;
 1 1 1 0 1 0 0 0 1 0 &lt;br /&gt;
 0 1 0 1 0 1 0 1 1 0 &lt;br /&gt;
 0 1 0 0 1 0 2 0 1 0 &lt;br /&gt;
 0 1 0 1 0 1 0 1 1 1 &lt;br /&gt;
 1 1 0 0 1 0 1 1 2 1 &lt;br /&gt;
 0 1 2 1 0 0 0 1 1 1 &lt;br /&gt;
 1 1 1 0 1 0 0 0 1 0&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def attack_positions_pawn(x, y, color, n):&lt;br /&gt;
    attacks = []&lt;br /&gt;
    if color == &amp;#039;white&amp;#039;:&lt;br /&gt;
        if x &amp;gt; 0 and y &amp;gt; 0:&lt;br /&gt;
            attacks.append((x - 1, y - 1))&lt;br /&gt;
        if x &amp;gt; 0 and y &amp;lt; n - 1:&lt;br /&gt;
            attacks.append((x - 1, y + 1))&lt;br /&gt;
    else:  # black&lt;br /&gt;
        if x &amp;lt; n - 1 and y &amp;gt; 0:&lt;br /&gt;
            attacks.append((x + 1, y - 1))&lt;br /&gt;
        if x &amp;lt; n - 1 and y &amp;lt; n - 1:&lt;br /&gt;
            attacks.append((x + 1, y + 1))&lt;br /&gt;
    return attacks&lt;br /&gt;
&lt;br /&gt;
def attack_positions_king(x, y, n):&lt;br /&gt;
    attacks = []&lt;br /&gt;
    for dx in range(-1, 2):&lt;br /&gt;
        for dy in range(-1, 2):&lt;br /&gt;
            if dx == 0 and dy == 0:&lt;br /&gt;
                continue&lt;br /&gt;
            if 0 &amp;lt;= x + dx &amp;lt; n and 0 &amp;lt;= y + dy &amp;lt; n:&lt;br /&gt;
                attacks.append((x + dx, y + dy))&lt;br /&gt;
    return attacks&lt;br /&gt;
&lt;br /&gt;
def attack_positions_knight(x, y, n):&lt;br /&gt;
    moves = [(2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1)]&lt;br /&gt;
    attacks = []&lt;br /&gt;
    for dx, dy in moves:&lt;br /&gt;
        if 0 &amp;lt;= x + dx &amp;lt; n and 0 &amp;lt;= y + dy &amp;lt; n:&lt;br /&gt;
            attacks.append((x + dx, y + dy))&lt;br /&gt;
    return attacks&lt;br /&gt;
&lt;br /&gt;
def attack_positions_bishop(x, y, n):&lt;br /&gt;
    attacks = []&lt;br /&gt;
    for i in range(1, n):&lt;br /&gt;
        if 0 &amp;lt;= x + i &amp;lt; n and 0 &amp;lt;= y + i &amp;lt; n:&lt;br /&gt;
            attacks.append((x + i, y + i))&lt;br /&gt;
        if 0 &amp;lt;= x - i &amp;lt; n and 0 &amp;lt;= y + i &amp;lt; n:&lt;br /&gt;
            attacks.append((x - i, y + i))&lt;br /&gt;
        if 0 &amp;lt;= x + i &amp;lt; n and 0 &amp;lt;= y - i &amp;lt; n:&lt;br /&gt;
            attacks.append((x + i, y - i))&lt;br /&gt;
        if 0 &amp;lt;= x - i &amp;lt; n and 0 &amp;lt;= y - i &amp;lt; n:&lt;br /&gt;
            attacks.append((x - i, y - i))&lt;br /&gt;
    return attacks&lt;br /&gt;
&lt;br /&gt;
def attack_positions_rook(x, y, n):&lt;br /&gt;
    attacks = []&lt;br /&gt;
    for i in range(1, n):&lt;br /&gt;
        if 0 &amp;lt;= x + i &amp;lt; n:&lt;br /&gt;
            attacks.append((x + i, y))&lt;br /&gt;
        if 0 &amp;lt;= x - i &amp;lt; n:&lt;br /&gt;
            attacks.append((x - i, y))&lt;br /&gt;
        if 0 &amp;lt;= y + i &amp;lt; n:&lt;br /&gt;
            attacks.append((x, y + i))&lt;br /&gt;
        if 0 &amp;lt;= y - i &amp;lt; n:&lt;br /&gt;
            attacks.append((x, y - i))&lt;br /&gt;
    return attacks&lt;br /&gt;
&lt;br /&gt;
def attack_positions_queen(x, y, n):&lt;br /&gt;
    return attack_positions_bishop(x, y, n) + attack_positions_rook(x, y, n)&lt;br /&gt;
&lt;br /&gt;
def is_attacked(board, x, y):&lt;br /&gt;
    return board[x][y] == 1&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # Citirea dimensiunii tablei de șah&lt;br /&gt;
    n = int(input().strip())&lt;br /&gt;
    &lt;br /&gt;
    # Citirea numărului de piese&lt;br /&gt;
    m = int(input().strip())&lt;br /&gt;
    &lt;br /&gt;
    # Inițializarea tablei de șah&lt;br /&gt;
    board = [[0] * n for _ in range(n)]&lt;br /&gt;
    &lt;br /&gt;
    # Citirea pieselor și plasarea lor pe tabla de șah&lt;br /&gt;
    for _ in range(m):&lt;br /&gt;
        piece_info = input().strip().split()&lt;br /&gt;
        piece_type = piece_info[0]&lt;br /&gt;
        x = int(piece_info[1]) - 1  # Transformare la index 0&lt;br /&gt;
        y = int(piece_info[2]) - 1  # Transformare la index 0&lt;br /&gt;
        color = piece_info[3] if len(piece_info) &amp;gt; 3 else None  # doar pentru pion&lt;br /&gt;
        &lt;br /&gt;
        # Marcare poziție ocupată&lt;br /&gt;
        board[x][y] = 2&lt;br /&gt;
        &lt;br /&gt;
        # Obținerea pozițiilor atacate&lt;br /&gt;
        if piece_type == &amp;quot;pion&amp;quot;:&lt;br /&gt;
            attacks = attack_positions_pawn(x, y, color, n)&lt;br /&gt;
        elif piece_type == &amp;quot;rege&amp;quot;:&lt;br /&gt;
            attacks = attack_positions_king(x, y, n)&lt;br /&gt;
        elif piece_type == &amp;quot;regina&amp;quot;:&lt;br /&gt;
            attacks = attack_positions_queen(x, y, n)&lt;br /&gt;
        elif piece_type == &amp;quot;nebun&amp;quot;:&lt;br /&gt;
            attacks = attack_positions_bishop(x, y, n)&lt;br /&gt;
        elif piece_type == &amp;quot;tura&amp;quot;:&lt;br /&gt;
            attacks = attack_positions_rook(x, y, n)&lt;br /&gt;
        elif piece_type == &amp;quot;cal&amp;quot;:&lt;br /&gt;
            attacks = attack_positions_knight(x, y, n)&lt;br /&gt;
        &lt;br /&gt;
        # Marcare poziții atacate&lt;br /&gt;
        for ax, ay in attacks:&lt;br /&gt;
            board[ax][ay] = max(board[ax][ay], 1)&lt;br /&gt;
    &lt;br /&gt;
    # Citirea coordonatelor ce trebuiesc verificate&lt;br /&gt;
    t = int(input().strip())&lt;br /&gt;
    for _ in range(t):&lt;br /&gt;
        x, y = map(int, input().strip().split())&lt;br /&gt;
        x -= 1  # Transformare la index 0&lt;br /&gt;
        y -= 1  # Transformare la index 0&lt;br /&gt;
        &lt;br /&gt;
        if board[x][y] == 2:&lt;br /&gt;
            print(&amp;quot;ocupata&amp;quot;)&lt;br /&gt;
        elif board[x][y] == 1:&lt;br /&gt;
            print(&amp;quot;atacata&amp;quot;)&lt;br /&gt;
        else:&lt;br /&gt;
            print(&amp;quot;neatacata&amp;quot;)&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>