From ebb7f9ba04c38fd950f82beb54f962a7d71b1282 Mon Sep 17 00:00:00 2001 From: Frederick Chen Date: Sat, 19 Apr 2025 10:09:51 +0800 Subject: [PATCH] AtCoder Beginner Contest 391 https://atcoder.jp/contests/abc391 Signed-off-by: Frederick Chen --- atcoder/abc391/A_Lucky_Direction.cpp | 30 +++++++++++++++++ atcoder/abc391/B_Seek_Grid.cpp | 48 +++++++++++++++++++++++++++ atcoder/abc391/C_Pigeonhole_Query.cpp | 32 ++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 atcoder/abc391/A_Lucky_Direction.cpp create mode 100644 atcoder/abc391/B_Seek_Grid.cpp create mode 100644 atcoder/abc391/C_Pigeonhole_Query.cpp diff --git a/atcoder/abc391/A_Lucky_Direction.cpp b/atcoder/abc391/A_Lucky_Direction.cpp new file mode 100644 index 0000000..c264b1e --- /dev/null +++ b/atcoder/abc391/A_Lucky_Direction.cpp @@ -0,0 +1,30 @@ +#include +#define lo long long +#define INF INT_MAX +#define LLM LONG_LONG_MAX + +using namespace std; +const int N = 1e7 + 10; +/* + toothless. #17 + @fredcss_dev +*/ + +map mp; + +string n; + +signed main() +{ + mp["N"] = "S"; + mp["E"] = "W"; + mp["W"] = "E"; + mp["S"] = "N"; + mp["NE"] = "SW"; + mp["NW"] = "SE"; + mp["SE"] = "NW"; + mp["SW"] = "NE"; + cin >> n; + cout << mp[n]; + return 0; +} \ No newline at end of file diff --git a/atcoder/abc391/B_Seek_Grid.cpp b/atcoder/abc391/B_Seek_Grid.cpp new file mode 100644 index 0000000..f66753e --- /dev/null +++ b/atcoder/abc391/B_Seek_Grid.cpp @@ -0,0 +1,48 @@ +#include +#define lo long long +#define INF INT_MAX +#define LLM LONG_LONG_MAX + +using namespace std; +const int N = 1e7 + 10; +/* + toothless. #17 + @fredcss_dev +*/ + +signed main() { + int N, M; + cin >> N >> M; + + vector > S(N, vector(N)); + vector > T(M, vector(M)); + for (int i = 0; i < N; ++i) { + for (int j = 0; j < N; ++j) { + cin >> S[i][j]; + } + } + for (int i = 0; i < M; ++i) { + for (int j = 0; j < M; ++j) { + cin >> T[i][j]; + } + } + for (int a = 0; a <= N - M; ++a) { + for (int b = 0; b <= N - M; ++b) { + bool match = true; + for (int i = 0; i < M; ++i) { + for (int j = 0; j < M; ++j) { + if (S[a + i][b + j] != T[i][j]) { + match = false; + break; + } + } + if (!match) break; + } + if (match) { + cout << a + 1 << " " << b + 1 << endl; + } + } + } + + return 0; +} \ No newline at end of file diff --git a/atcoder/abc391/C_Pigeonhole_Query.cpp b/atcoder/abc391/C_Pigeonhole_Query.cpp new file mode 100644 index 0000000..cf6fd51 --- /dev/null +++ b/atcoder/abc391/C_Pigeonhole_Query.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; + +int n, q, mp[10005], g[10005], cnt = 0, a, b, c; + +int main() +{ + cin >> n >> q; + for (int i = 0; i <= n; i++) + { + mp[i] = 1; + g[i] = i; + } + while (q--) + { + cin >> a; + if (a == 1) + { + cin >> b >> c; + if (mp[g[b]] == 2) + cnt--; + if (mp[c] == 1) + cnt++; + mp[g[b]]--; + mp[c]++; + g[b] = c; + } + else if (a == 2) + cout << cnt << endl; + return 0; + } \ No newline at end of file