Skip to content

Commit

Permalink
Round 4 tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaci committed Feb 26, 2024
1 parent 5f74eb6 commit 4f563df
Show file tree
Hide file tree
Showing 43 changed files with 1,414 additions and 1 deletion.
125 changes: 124 additions & 1 deletion tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,71 @@ <h3>Feladatok és megoldások</h3>
<!-- Main -->
<section id="main" class="container">

<div class="box">
<h3>Kódkupa 2023-24 4. online forduló</h3>
<p>
Alább láthatók a feladatszövegek és a mintamegoldások. A feladatokat gyakorlásként meg lehet oldani az <a href="https://njudge.hu/task_archive#category102">njudge</a> kiértékelő rendszerben. <br>
</p>
<details>
<summary>Megtekintés</summary>
<ol>
<li>Kocsirendező (cars)
<ul>
<li><a href="/tasks/2024/round4/cars.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/cars.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4/cars.py">Python megoldás</a></li>
</ul>
</li>
<li>Négyszög (quadrilateral)
<ul>
<li><a href="/tasks/2024/round4/quadrilateral.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/quadrilateral.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4/quadrilateral.py">Python megoldás</a></li>
</ul>
</li>
<li>Egy trikolór mestermű (grid)
<ul>
<li><a href="/tasks/2024/round4/grid.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/grid.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4/grid.py">Python megoldás</a></li>
</ul>
</li>
<li>Stefan sakkmesteri ambíciói (chess3)
<ul>
<li><a href="/tasks/2024/round4/chess3.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/chess3.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4/chess3.py">Python megoldás</a></li>
</ul>
</li>
<li>K-léptű ősök (treeancestor)
<ul>
<li><a href="/tasks/2024/round4/treeancestor.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/treeancestor.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4/treeancestor.py">Python megoldás</a></li>
</ul>
</li>
<li>Jobstown-i milliomos (jobs)
<ul>
<li><a href="/tasks/2024/round4/jobs.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/jobs.cpp">C++ megoldás</a></li>
</ul>
</li>
<li>Kutyavetélkedő 2 (dogtrick2)
<ul>
<li><a href="/tasks/2024/round4/dogtrick2.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/dogtrick2.cpp">C++ megoldás</a></li>
</ul>
</li>
<li>Az IKPC legerősebb csapata (strongestteams)
<ul>
<li><a href="/tasks/2024/round4/strongestteams.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4/strongestteams.cpp">C++ megoldás</a></li>
</ul>
</li>
</ol>
</details>
</div>

<div class="box">
<h3>Kódkupa 2023-24 3. online forduló</h3>
<p>
Expand Down Expand Up @@ -276,9 +341,67 @@ <h3>Kódkupa 2023-24 1. online forduló</h3>
</details>
</div>

<div class="box">
<h3>ProgramPohár 2023-24 4. online forduló</h3>
<p>Alább láthatók a feladatszövegek és a mintamegoldások. A feladatokat gyakorlásként meg lehet oldani az <a href="https://njudge.hu/task_archive#category103">njudge</a> kiértékelő rendszerben. </p>
<details>
<summary>Megtekintés</summary>
<ol>
<li>Plusz (plusz)
<ul>
<li><a href="/tasks/2024/round4_pp/plusz.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/plusz.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/plusz.py">Python megoldás</a></li>
</ul>
</li>
<li>Gyorsolvasó-verseny (olvasoverseny)
<ul>
<li><a href="/tasks/2024/round4_pp/olvasoverseny.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/olvasoverseny.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/olvasoverseny.py">Python megoldás</a></li>
</ul>
</li>
<li>Kocsirendező (cars-pp)
<ul>
<li><a href="/tasks/2024/round4_pp/cars-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/cars-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/cars-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Négyszög (quadrilateral-pp)
<ul>
<li><a href="/tasks/2024/round4_pp/quadrilateral-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/quadrilateral-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/quadrilateral-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Egy trikolór mestermű (grid-pp)
<ul>
<li><a href="/tasks/2024/round4_pp/grid-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/grid-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/grid-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Stefan sakkmesteri ambíciói (chess3-pp)
<ul>
<li><a href="/tasks/2024/round4_pp/chess3-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/chess3-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/chess3-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Jobstown-i milliomos (jobs-pp)
<ul>
<li><a href="/tasks/2024/round4_pp/jobs-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round4_pp/jobs-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round4_pp/jobs-pp.py">Python megoldás</a></li>
</ul>
</li>
</ol>
</details>
</div>

<div class="box">
<h3>ProgramPohár 2023-24 2. online forduló</h3>
<h3>ProgramPohár 2023-24 3. online forduló</h3>
<p>Alább láthatók a feladatszövegek és a mintamegoldások. A feladatokat gyakorlásként meg lehet oldani az <a href="https://njudge.hu/task_archive#category99">njudge</a> kiértékelő rendszerben. </p>
<details>
<summary>Megtekintés</summary>
Expand Down
40 changes: 40 additions & 0 deletions tasks/2024/round4/cars.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @check-accepted: examples Nsmall no-limits
/**
* author: BERNARD B.01
**/
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

#ifdef B01
#include "deb.h"
#else
#define deb(...)
#endif

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
int pos = 0;
while (p[pos] != 1) {
pos += 1;
}
for (int i = 0; i < n; i++) {
if (p[(pos + i) % n] != i + 1) {
cout << -1 << '\n';
return 0;
}
}
cout << (n - pos) % n << '\n';
return 0;
}
Binary file added tasks/2024/round4/cars.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions tasks/2024/round4/cars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
# @check-accepted: examples Nsmall no-limits
from sys import stdin, stdout

def rd(): return stdin.readline().strip()
def rdl(x): return map(x, rd().split())
def wt(x): stdout.write(str(x))
def wtl(x): wt(str(x) + '\n')

n = int(rd())
p = list(rdl(int));
pos = p.index(1)
for i in range(n):
if p[(pos + i) % n] != i + 1:
wtl(-1)
exit()
wtl((n - pos) % n)
105 changes: 105 additions & 0 deletions tasks/2024/round4/chess3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int t;
cin >> t;

for(; t; t--)
{
char mat[9][9];
for(int i = 0; i <= 7; i++)
for(int j = 0; j <= 7; j++)
cin >> mat[i][j];

bool underThreat = 0;
for(int i = 0; i <= 7; i++)
for(int j = 0; j <= 7; j++)
{
if(mat[i][j] == 'P') // pawn
{
if(j > 0 && i > 0 && mat[i-1][j-1] == 'q')
underThreat = 1;
if(j < 7 && i > 0 && mat[i-1][j+1] == 'q')
underThreat = 1;
}
if(mat[i][j] == 'N') // knight
{
for(int dirx = -2; dirx <= 2; dirx++)
for(int diry = -2; diry <= 2; diry++)
{
if(abs(dirx) + abs(diry) == 3)
{
if(i + dirx >= 0 && i + dirx <= 7 && j + diry >= 0 && j + diry <= 7)
{
if(mat[i + dirx][j + diry] == 'q')
underThreat = 1;
}
}
}
}
if(mat[i][j] == 'B' || mat[i][j] == 'Q') // bishop or queen
{
for(int dirx = -1; dirx <= 1; dirx++)
for(int diry = -1; diry <= 1; diry++)
{
if(abs(dirx) + abs(diry) == 2)
{
int xa = i + dirx;
int ya = j + diry;
while(xa >= 0 && xa <= 7 && ya >= 0 && ya <= 7)
{
if(mat[xa][ya] == 'q')
{
underThreat = 1;
break;
}
if(mat[xa][ya] != '.')
break;
xa += dirx;
ya += diry;
}
}
}
}
if(mat[i][j] == 'R' || mat[i][j] == 'Q') // rook or queen
{
for(int dirx = -1; dirx <= 1; dirx++)
for(int diry = -1; diry <= 1; diry++)
{
if(abs(dirx) + abs(diry) == 1)
{
int xa = i + dirx;
int ya = j + diry;
while(xa >= 0 && xa <= 7 && ya >= 0 && ya <= 7)
{
if(mat[xa][ya] == 'q')
{
underThreat = 1;
break;
}
if(mat[xa][ya] != '.')
break;
xa += dirx;
ya += diry;
}
}
}
}
}
if(underThreat)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}

Empty file added tasks/2024/round4/chess3.pdf
Empty file.
65 changes: 65 additions & 0 deletions tasks/2024/round4/chess3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
#

def solv():
board=[]
for i in range(8):
board.append(input())
for x in range(64):
i=x//8
j=x%8
if board[i][j]=='q':
queenx,queeny=i,j
break
#Knight
for x,y in [(1,2),(2,1),(-1,2),(2,-1),(1,-2),(-2,1),(-1,-2),(-2,-1)]:
if 0<=x+queenx<=7 and 0<=y+queeny<=7:
if board[x+queenx][y+queeny]=='N':
print('YES')
return
#Pawn
if 0<=1+queenx<=7 and 0<=1+queeny<=7:
if board[1+queenx][1+queeny]=='P':
print('YES')
return
if 0<=1+queenx<=7 and 0<=-1+queeny<=7:
if board[1+queenx][-1+queeny]=='P':
print('YES')
return
# horizontal/vertical
for a,b in [(0,1),(1,0),(-1,0),(0,-1)]:
x,y=queenx,queeny
for c in range(1,8):
x+=a
y+=b
if 0 <= y < 8 and 0 <= x < 8:
if board[x][y] !='.':
if board[x][y] in ['R','Q']:
print('YES')
return
else:
break
else:
break
# diagonal but not Pawns
for a,b in [(1,1),(1,-1),(-1,1),(-1,-1)]:
x,y=queenx,queeny
for c in range(1,8):
x+=a
y+=b
if 0 <= y < 8 and 0 <= x < 8:
if board[x][y] !='.':
if board[x][y] in ['B','Q']:
print('YES')
return
else:
break
else:
break
print('NO')



T = int(input().strip())
for _ in range(T):
solv()
Loading

0 comments on commit 4f563df

Please sign in to comment.