Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

25-yuyu0830 #92

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"files.associations": {
"queue": "cpp"
"queue": "cpp",
"vector": "cpp"
}
}
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
| 19์ฐจ์‹œ | 2024.07.12 | ์žฌ๊ท€ | [์šฐ์ˆ˜๋งˆ์„](https://www.acmicpc.net/problem/1949) | - |
| 20์ฐจ์‹œ | 2024.07.22 | LIS | [๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 5](https://www.acmicpc.net/problem/14003) | - |
| 21์ฐจ์‹œ | 2024.07.23 | ์ˆ˜ํ•™ | [1์˜ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ](https://www.acmicpc.net/problem/9527) | - |
| 25์ฐจ์‹œ | 2024.08.17 | ์ˆ˜ํ•™ | [์‹ ๊ธฐํ•œ ์†Œ์ˆ˜](https://www.acmicpc.net/problem/2023) | - |
---
123 changes: 123 additions & 0 deletions yuyu0830/๊ตฌํ˜„/12100.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <iostream>

using namespace std;

int map[21][21] = {0, };
int n, ans = 0;
int dir[4][2] = {
{0, 1},
{0, -1},
{1, 0},
{-1, 0}
};

bool isin(int t) { return t >= 0 && t < n; }

bool move(int m[21][21], int d) {
// ๋ฐ˜ํ™˜ ๊ฐ’(e)์€ ์›€์ง์ž„ ์—ฌ๋ถ€
bool e = false;

// vertical : ์›€์ง์ž„ ๋ฐฉํ–ฅ์ด ๊ฐ€๋กœ์ธ์ง€ ์„ธ๋กœ์ธ์ง€
// plus : ์›€์ง์ž„ ๋ฐฉํ–ฅ์ด + ๋ฐฉํ–ฅ์ธ์ง€ - ๋ฐฉํ–ฅ์ธ์ง€
bool vertical = d < 2, plus = d % 2 == 0;

// ํ•œ ๋ฒˆ ๋”ํ•ด์ง„ ๋ถ€๋ถ„์€ ๋‹ค์‹œ ๋”ํ•ด์ง€๋ฉด ์•ˆ๋˜๋‹ˆ๊นŒ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ
bool visited[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
visited[i][j] = 0;

for (int i = 0; i < n; i++) {
// ํ˜„์žฌ ํƒ์ƒ‰ ์œ„์น˜์˜ x, y ์ขŒํ‘œ๊ฐ’
int x = vertical ? i : (plus ? 1 : n - 2);
int y = vertical ? (plus ? 1 : n - 2) : i;

// ํƒ์ƒ‰ ๋ฒ”์œ„ ์•ˆ์— ์žˆ๋Š” ๋™์•ˆ๋งŒ ํƒ์ƒ‰
while (isin(vertical ? y : x)) {
// ํ˜„์žฌ ํƒ์ƒ‰ ์œ„์น˜์— ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ์ด๋™ ํ•ด์•ผํ•จ
if (m[x][y]) {
// ๊ฐ’ ์ €์žฅ ๋ฐ ํ˜„์žฌ ํƒ์ƒ‰ ์œ„์น˜ 0์œผ๋กœ
int tmp = m[x][y];
m[x][y] = 0;

// ์–ด๋””๊นŒ์ง€ ์ด๋™ํ• ์ง€ ํƒ์ƒ‰ํ•  ์ž„์‹œ ํƒ์ƒ‰ ์œ„์น˜์˜ x, y ์ขŒํ‘œ๊ฐ’
int tx = x - dir[d][0];
int ty = y - dir[d][1];

while (true) {
// ์ž„์‹œ ํƒ์ƒ‰ ์œ„์น˜์— ๊ฐ’์ด ์žˆ๋‹ค๋ฉด
if (m[tx][ty]) {
// ๊ฐ’์ด ์žˆ๊ณ , ํ˜„์žฌ ํƒ์ƒ‰ ์œ„์น˜์™€ ๊ฐ’์ด ๊ฐ™๊ณ , ๋ฐฉ๋ฌธํ•œ ์ ์ด ์—†๋‹ค๋ฉด
// ์ž„์‹œ ํƒ์ƒ‰ ์œ„์น˜์˜ ๊ฐ’์— ๋”ํ•ด์ง
if (tmp == m[tx][ty] && !visited[tx][ty]) {
e = true;
visited[tx][ty] = true;
break;
}
// ๊ฐ’์ด ๋‹ค๋ฅด๊ฑฐ๋‚˜, ๋ฐฉ๋ฌธํ•œ ์ ์ด ์žˆ์œผ๋ฉด
// ์ž„์‹œ ํƒ์ƒ‰ ์œ„์น˜์—์„œ ํ•œ ์นธ ์ „์œผ๋กœ ์ด๋™
else {
tx += dir[d][0];
ty += dir[d][1];
break;
}
}

// ๋” ์ด๋™ ๊ฐ€๋Šฅํ•œ์ง€ ์ฒดํฌ
if (!isin(vertical ? ty - dir[d][1]: tx - dir[d][0]))
break;

// ์›€์ง์ž„ ์—ฌ๋ถ€ ์ฒดํฌ
e = true;

// ์ž„์‹œ ํƒ์ƒ‰ ์œ„์น˜ ์ด๋™
tx -= dir[d][0];
ty -= dir[d][1];
}

// ์ž„์‹œ ํƒ์ƒ‰ ์œ„์น˜๊นŒ์ง€ ์ด๋™ ์ฒ˜๋ฆฌ
m[tx][ty] += tmp;
// ์ตœ๋Œ€ ๊ฐ’ ์ฒ˜๋ฆฌ
ans = max(ans, m[tx][ty]);
}

// ํ˜„์žฌ ํƒ์ƒ‰ ์œ„์น˜ ์ด๋™
x += dir[d][0];
y += dir[d][1];
}
}

return e;
}

void f(int m[21][21], int depth) {
// depth๊ฐ€ 5๊ฐ€ ๋˜๋ฉด ํƒ์ƒ‰ ์ข…๋ฃŒ
if (depth == 5) return;

int tm[21][21];

for (int d = 0; d < 4; d++) {
// ์ž„์‹œ map ์ƒ์„ฑ
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
tm[i][j] = m[i][j];

// ๋งŒ์•ฝ ์›€์ง์ž„์ด ์—†์œผ๋ฉด ๊ตณ์ด ๋” ํƒ์ƒ‰ํ•˜์ง€ ์•Š๋Š”๋‹ค.
if (move(tm, d))
f(tm, depth + 1);

}
}

int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
ans = max(ans, map[i][j]);
}
}

f(map, 0);
printf("%d\n", ans);
}
46 changes: 46 additions & 0 deletions yuyu0830/์ˆ˜ํ•™/2023.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool notPrime[10000] = {0, };

bool isPrime(int t) {
for (int i = 2; i <= sqrt(t); i++) {
if (notPrime[i]) continue;
if (t % i == 0) {
notPrime[i] = true;
return false;
}
}
return true;
}

int main() {
int n; cin >> n;

int start = 1;

vector<int> v[2];
bool e = false;

v[1].push_back(0);

for (int i = 0; i < n; i++) {
for (int p : v[!e]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์„ ์ฒ˜์Œ ๋ดค์„ ๋•Œ ๋ฌด์—‡์ธ๊ฐ€ ํ–ˆ์Šต๋‹ˆ๋‹ค.
์ด์ œ๋Š” ์—ฌ๋Ÿฌ๋ฒˆ ๋ณด์•˜์„ ๋•Œ ์ดํ•ด๊ฐ€ ๊ฐ€๋”๊ตฐ์š”...
e๋Š” true, false ๋กœ 1, 0์„ ๋ฒˆ๊ฐˆ์•„ ๊ฐ„๋‹ค.
์™ผ์ชฝ ์ž๋ฆฟ์ˆ˜๋ถ€ํ„ฐ 0๋ถ€ํ„ฐ 9๊นŒ์ง€ ๋น„๊ตํ•˜๋ฉด์„œ ์†Œ์ˆ˜์ธ ๊ฒƒ๋“ค๋งŒ ์ง‘์–ด ๋„ฃ๋Š” ํ˜•์‹์ด์—ˆ๋„ค์š”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ทธ๋Ÿผ์š” :)
์ „๊ธฐํ†ต๋‹ญ๊ตฌ์ด๋ผ๋Š” ํ‘œํ˜„์ด ๋” ์žฌ๋ฐŒ๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ์š” ใ…‹ใ…‹ใ…‹

for (int t = 0; t < 10; t++) {
int cur = p * 10 + t;
if (isPrime(cur)) v[e].push_back(cur);
}
}

v[!e].clear();
e = !e;
}

for (int i : v[e])
printf("%d\n", i);
}