๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)315

[๋ฐฑ์ค€,c++] 1188๋ฒˆ - ์Œ์‹ ํ‰๋ก ๊ฐ€ ๋ฌธ์ œ 1188๋ฒˆ: ์Œ์‹ ํ‰๋ก ๊ฐ€ ์ฒซ์งธ ์ค„์— ์†Œ์‹œ์ง€์˜ ์ˆ˜ N๊ณผ ํ‰๋ก ๊ฐ€์˜ ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N, M ≤ 100) www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; int gcd(int a,int b){ if(b==0) return a; else return gcd(b,a%b); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int a,b; cin>>a>>b; cout 2021. 11. 22.
[๋ฐฑ์ค€,c++] 15650๋ฒˆ - N๊ณผ M (2) ๋ฌธ์ œ 15650๋ฒˆ: N๊ณผ M (2) ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๋ฌธ์ œ์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ˆ˜์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค. ์ค‘๋ณต๋˜๋Š” ์ˆ˜์—ด์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์ถœ๋ ฅํ•˜๋ฉด ์•ˆ๋˜๋ฉฐ, ๊ฐ ์ˆ˜์—ด์€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ์ˆ˜์—ด์€ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ถœ๋ ฅํ•ด www.acmicpc.net ์ฝ”๋“œ #include #include #define max 9 using namespace std; int N, M; int arr[max]; bool visited[max]; void dfs(int num,int start) { if (start == M) { for (int i = 0; i < M; i++) { cout M; dfs(1,0); } 2021. 11. 17.
[๋ฐฑ์ค€,c++] 15649๋ฒˆ - N๊ณผ M(1) ๋ฌธ์ œ 15649๋ฒˆ: N๊ณผ M (1) ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๋ฌธ์ œ์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ˆ˜์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค. ์ค‘๋ณต๋˜๋Š” ์ˆ˜์—ด์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์ถœ๋ ฅํ•˜๋ฉด ์•ˆ๋˜๋ฉฐ, ๊ฐ ์ˆ˜์—ด์€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ์ˆ˜์—ด์€ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ถœ๋ ฅํ•ด www.acmicpc.net ์ฝ”๋“œ #include #include #define max 9 using namespace std; int arr[max]; bool visited[max]; int N, M; void dfs(int cnt) { if (cnt == M) { for (int i = 0; i < M; i++) { cout M; dfs(0); } 2021. 11. 17.
[๋ฐฑ์ค€,c++] 15643๋ฒˆ - Yee ๋ฌธ์ œ 15643๋ฒˆ: Yee Ba ba ba ba, ba, ba ba, baa, ba ba Ba ba ba ba, ba, ba ba Yee Ba ba ba ba, ba, ba ba, baa, ba ba Ba ba ba ba, ba, ba ba Yee Ba ba ba ba, ba, ba ba, baa, ba ba Ba ba ba ba, ba, ba ba Yee Ba ba ba ba, ba, ba ba, baa, ba ba Ba ba ba ba, ba, ba ba Yee Ba ba ba www.acmicpc.net ํ’€์ด ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ์ด ๋…ธ๋ž˜ ๋…ธ์ด๋กœ์ œ ๊ฑธ๋ฆผ yee~~~~~ ํ•ด๋‹น ๋ฌธ์ œ ์œ ํŠœ๋ธŒ ์˜์ƒ 1์‹œ๊ฐ„ 46๋ถ„ 17์ดˆ๋ถ€๋ถ„์— ์ผ์‹œ์ •์ง€ ํ•˜๋ฉด ์ •๋‹ต์ด ๋ณด์ž…๋‹ˆ๋‹ค..... ๊ทธ๊ฒƒ๋งˆ์ € ๊ท€์ฐฎ์€ ์‚ฌ๋žŒ๋“ค์„ ์œ„ํ•ด์„œ... ๋”๋ณด.. 2021. 11. 17.
[๋ฐฑ์ค€,c++] 15552๋ฒˆ - ๋น ๋ฅธA+B ๋ฌธ์ œ 15552๋ฒˆ: ๋น ๋ฅธ A+B ์ฒซ ์ค„์— ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. T๋Š” ์ตœ๋Œ€ 1,000,000์ด๋‹ค. ๋‹ค์Œ T์ค„์—๋Š” ๊ฐ๊ฐ ๋‘ ์ •์ˆ˜ A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. A์™€ B๋Š” 1 ์ด์ƒ, 1,000 ์ดํ•˜์ด๋‹ค. www.acmicpc.net ์ฝ”๋“œ #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T-- > 0) { int A, B; cin >> A >> B; cout 2021. 11. 17.
[๋ฐฑ์ค€,c++] 15482๋ฒˆ - ํ•œ๊ธ€ LCS ๋ฌธ์ œ 15482๋ฒˆ: ํ•œ๊ธ€ LCS ์ฒซ์งธ ์ค„๊ณผ ๋‘˜์งธ ์ค„์— ๋‘ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฌธ์ž์—ด์€ ์ตœ๋Œ€ 1000๊ธ€์ž์ด๊ณ , ์œ ๋‹ˆ์ฝ”๋“œ U+AC00(๊ฐ€)๋ถ€ํ„ฐ U+D7A3(ํžฃ)๊นŒ์ง€๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, UTF-8๋กœ ์ธ์ฝ”๋”ฉ ๋˜์–ด ์žˆ๋‹ค. www.acmicpc.net ์ฝ”๋“œ #include using namespace std; int dp[3001][3001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); string A,B; cin>>A>>B; for(int i=3; i 2021. 11. 17.
[๋ฐฑ์ค€,c++] 1547๋ฒˆ - ๊ณต ๋ฌธ์ œ 1547๋ฒˆ: ๊ณต ์ฒซ์งธ ์ค„์— ์ปต์˜ ์œ„์น˜๋ฅผ ๋ฐ”๊พผ ํšŸ์ˆ˜ M์ด ์ฃผ์–ด์ง€๋ฉฐ, M์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์—๋Š” ์ปต์˜ ์œ„์น˜๋ฅผ ๋ฐ”๊พผ ๋ฐฉ๋ฒ• X์™€ Y๊ฐ€ ์ฃผ์–ด์ง€๋ฉฐ, X๋ฒˆ ์ปต๊ณผ Y๋ฒˆ ์ปต์˜ ์œ„์น˜๋ฅผ ์„œ๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ www.acmicpc.net ์ฝ”๋“œ #include #include #include using namespace std; vectorv(4); int main() { int M; cin >> M; v[1] = 1; v[2] = 0; v[3] = 0; for (int i = 0; i > a >> b; swap(v[a], v[b]); } cout 2021. 11. 17.
[๋ฐฑ์ค€,c++] 1541๋ฒˆ - ์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ ๋ฌธ์ œ 1541๋ฒˆ: ์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ ์ฒซ์งธ ์ค„์— ์‹์ด ์ฃผ์–ด์ง„๋‹ค. ์‹์€ ‘0’~‘9’, ‘+’, ๊ทธ๋ฆฌ๊ณ  ‘-’๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ฐ€์žฅ ์ฒ˜์Œ๊ณผ ๋งˆ์ง€๋ง‰ ๋ฌธ์ž๋Š” ์ˆซ์ž์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์—ฐ์†ํ•ด์„œ ๋‘ ๊ฐœ ์ด์ƒ์˜ ์—ฐ์‚ฐ์ž๊ฐ€ ๋‚˜ํƒ€๋‚˜์ง€ ์•Š๊ณ , 5์ž๋ฆฌ๋ณด๋‹ค www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; string s, temp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> s; bool minus = false; int ans = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '-' || s[i] == '+') {//์—ฐ์‚ฐ์ž์ผ๋•Œ if (minus)ans .. 2021. 11. 17.
[๋ฐฑ์ค€,c++] 15240๋ฒˆ - Paint bucket ๋ฌธ์ œ 15240๋ฒˆ: Paint bucket One of the most time-saving operations when drawing on a computer (for example using Photoshop) is the “bucket fill” operation. When you select this tool and click on a (target) pixel of the image it will fill all the pixels that have the same color www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; int map[1001][1001]; int visited[1001][1001]; int ans; int Y,X,K; .. 2021. 11. 17.