[c++] ๋ฐฑ์ค€ 18809๋ฒˆ : Gaaaaaaaaaarden
Algorithm ๋ฌธ์ œ/BOJ 2020. 3. 26. 17:12

https://www.acmicpc.net/problem/18809 ์ฒซ๋ฒˆ์งธ ์ฝ”๋“œ #include #include #include #include using namespace std; struct seed { int y, x; }; int map[50][50]; vector landToSeed; vector Green; vector Red; int N, M, G, R; vector g; vector r; int dir_y[4] = {0,1,0,-1}; int dir_x[4] = {1,0,-1,0}; void printVector(vector& a) { // int์— land๋„ ๋„ฃ์„์ˆ˜ ์žˆ์„๊นŒ? vector::iterator iter; for (iter = a.begin(); iter != a.end(); i..

[์•Œ๊ณ ๋ฆฌ์ฆ˜] ๊ณผ์ œ 3. Tony Hoare :: QuickSort ๋…ผ๋ฌธ ํ•ด์„ํ•˜๊ธฐ
์ปดํ“จํ„ฐ๊ณผํ•™ (CS)/Algorithm 2020. 3. 26. 16:56

QuickSort ๋…ผ๋ฌธ brief Part One: Theory ์ด sorting์€ ๋‘ ๊ฐœ์˜ ๊ฐ„๋‹จํ•œ ๋ณด์กฐ๋ฌธ์ œ๋กœ ๋‚˜๋‰˜์–ด ํ•ด๊ฒฐ๋  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๊ฐ ๋ฌธ์ œ๋Š” ์ด๋ฏธ ์•Œ๋ ค์ง„ ๋ฐฉ์‹์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋‹ค. Partition : key๊ฐ’์„ dividing line์— ๋”ฐ๋ผ ์œ„ ์•„๋ž˜๋กœ ๋‚˜๋ˆ„์–ด ์ด๋ถ„ํ•˜๋Š” ๊ฒƒ ์‹ค์ œ๋กœ ์ด dividing line์€ ํ”์น˜ ์•Š๊ณ , ์žˆ๋‹ค ํ• ์ง€๋ผ๋„ ์ฐพ๊ธฐ ํž˜๋“ ๋ฐ dividing line์ด ์กด์žฌํ•˜๊ณ  ๊ทธ๊ฒƒ์˜ ์œ„์น˜๋งŒ ์•ˆ๋‹ค๋ฉด item๋“ค์„ ์žฌ์ •๋ ฌํ•˜๊ธฐ๋Š” ์‰ฌ์›Œ์ง„๋‹ค. partition ๊ณผ์ • ์ •๋ ฌ๋˜์–ด์•ผํ•˜๋Š” ์•„์ดํ…œ์˜ ํ‚ค ์ค‘ ํŠน์ • ํ‚ค๋ฅผ ๊ณ ๋ฅธ๋‹ค. ์ด ํ‚ค๋Š” bound ๋ผ ๋ถˆ๋ฆฐ๋‹ค. dividing line ์•„๋ž˜์—๋Š” bound๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ key๊ฐ’์ด, ์œ„์ชฝ์—๋Š” ํฐ key ๊ฐ’์ด ์˜ค๊ฒŒ ํ•œ๋‹ค. dividing line์˜ ์œ„์น˜๋Š” ๋ฏธ๋ฆฌ ์•Œ ํ•„์š”..

[์•Œ๊ณ ๋ฆฌ์ฆ˜] ๊ณผ์ œ 2. 1000๋งŒ๊ฐœ ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์ •๋ ฌ ์‹œ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„
์ปดํ“จํ„ฐ๊ณผํ•™ (CS)/Algorithm 2020. 3. 25. 20:01

/* 2020-03-19 ์šฐํฌ์€ ์‚ฝ์ž…์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜ */ #define _CRT_SECURE_NO_WARNINGS #include #include #include #include int buffer[10000000]; // ์ „์—ญ ๋ณ€์ˆ˜๋กœ ๋„ฃ์–ด์•ผ stack overflow๊ฐ€ ๋‚˜์ง€ ์•Š์Œ void fileOpen() { FILE *fp = fopen("d://algorithm/unsorted10000000.txt", "r"); int i = 0; int tmp = 0; if (fp == NULL) { printf("ํŒŒ์ผ์„ ์—ด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.\n"); } while (fscanf(fp, "%d ", &tmp)!=EOF) { buffer[i++] = tmp; } fclose(fp); } void insertSortin..

[์•Œ๊ณ ๋ฆฌ์ฆ˜] ๊ณผ์ œ 1. ์‹œ๊ฐ„ ๋ณต์žก๋„ ๊ณ„์‚ฐ :: ๊ฐ ์‹œ๊ฐ„ ๋ณต์žก๋„์— ํ•ด๋‹นํ•˜๋Š” ์†Œ์š”์‹œ๊ฐ„์„ ๊ตฌํ•ด๋ณด์ž
์ปดํ“จํ„ฐ๊ณผํ•™ (CS)/Algorithm 2020. 3. 25. 19:52

์ฒซ๋ฒˆ์งธ ๊ณผ์ œ์ด๋‹ค. ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ f(n)์ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์†Œ์š”์‹œ๊ฐ„์ด 1 nanosecond == 10^(-9) second ์ด๋ผ๊ณ  ํ•  ๋•Œ, ์™ผ์ชฝ์— ํ‘œ์‹œ๋œ ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋Œ€ํ•ด ์œ„์ชฝ์˜ ์‹œ๊ฐ„ ๋‚ด์— ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์™„๋ฃŒ๋˜๋ ค๋ฉด ์ตœ๋Œ€๋กœ ์–ด๋–ค N๊นŒ์ง€ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์„์ง€ ์•Œ์•„๋ณด์ž. ๋Œ€ํ‘œ๋กœ ํ•˜๋‚˜๋ฅผ ๊ณ„์‚ฐํ•ด๋ณด๋ฉด 1sec๋Š” 10^(9) nanosec ์ด๋ฏ€๋กœ n^2์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ฐ–๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ n^2 = 10^(9) ๋กœ ๋‘๊ณ  ํ’€๋ฉด 1sec ๋งŒ์— ๊ณ„์‚ฐ๋  ์ˆ˜ ์žˆ๋Š” n ๊ฐ’์ด ๋‚˜์˜จ๋‹ค. n ๊ฐ’์€ ๋ชจ๋‘ ์ •์ˆ˜๋กœ ๊ฐ€์ •ํ•˜์˜€๋‹ค.

[c++] ๋ฐฑ์ค€ 18808๋ฒˆ : ์Šคํ‹ฐ์ปค ๋ถ™์ด๊ธฐ
Algorithm ๋ฌธ์ œ/BOJ 2020. 3. 21. 17:15

https://www.acmicpc.net/problem/18808 #include #include using namespace std; int n, m, k; int turn; int st_l, st_w; struct sticker { int x_len, y_len; }; void rotateSticker(vector& stic) { int width = stic[0].size(); int length = stic.size(); vector tmp(width, vector(length)); for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) { tmp[j][length-1-i] = stic[i][j]; } } stic = tmp; } ..

[c++]๋ฐฑ์ค€ 17836๋ฒˆ : ๊ณต์ฃผ๋‹˜์„ ๊ตฌํ•ด๋ผ!
Algorithm ๋ฌธ์ œ/BOJ 2020. 3. 21. 12:31

๋ฌธ์ œ : ๋ฐฑ์ค€ 17836๋ฒˆ _ ๊ณต์ฃผ๋‹˜์„ ๊ตฌํ•ด๋ผ! https://www.acmicpc.net/problem/17836 ์‹œ๊ฐ„ ์ œํ•œ ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ ์ œ์ถœ ์ •๋‹ต ๋งž์€ ์‚ฌ๋žŒ ์ •๋‹ต ๋น„์œจ 1 ์ดˆ 256 MB 2465 566 431 21.923% ๋ฌธ์ œ ์šฉ์‚ฌ๋Š” ๋งˆ์™•์ด ์ˆจ๊ฒจ๋†“์€ ๊ณต์ฃผ๋‹˜์„ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด (N, M) ํฌ๊ธฐ์˜ ์„ฑ ์ž…๊ตฌ (1,1)์œผ๋กœ ๋“ค์–ด์™”๋‹ค. ๋งˆ์™•์€ ์šฉ์‚ฌ๊ฐ€ ๊ณต์ฃผ๋ฅผ ์ฐพ์ง€ ๋ชปํ•˜๋„๋ก ์„ฑ์˜ ์—ฌ๋Ÿฌ ๊ตฐ๋ฐ ๋งˆ๋ฒ• ๋ฒฝ์„ ์„ธ์›Œ๋†“์•˜๋‹ค. ์šฉ์‚ฌ๋Š” ํ˜„์žฌ์˜ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฌด๊ธฐ๋กœ๋Š” ๋งˆ๋ฒ• ๋ฒฝ์„ ํ†ต๊ณผํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ๋งˆ๋ฒ• ๋ฒฝ์„ ํ”ผํ•ด (N, M) ์œ„์น˜์— ์žˆ๋Š” ๊ณต์ฃผ๋‹˜์„ ๊ตฌ์ถœํ•ด์•ผ๋งŒ ํ•œ๋‹ค. ๋งˆ์™•์€ ์šฉ์‚ฌ๋ฅผ ๊ดด๋กญํžˆ๊ธฐ ์œ„ํ•ด ๊ณต์ฃผ์—๊ฒŒ ์ €์ฃผ๋ฅผ ๊ฑธ์—ˆ๋‹ค. ์ €์ฃผ์— ๊ฑธ๋ฆฐ ๊ณต์ฃผ๋Š” T์‹œ๊ฐ„ ์ด๋‚ด๋กœ ์šฉ์‚ฌ๋ฅผ ๋งŒ๋‚˜์ง€ ๋ชปํ•œ๋‹ค๋ฉด ์˜์›ํžˆ ๋Œ๋กœ ๋ณ€ํ•˜๊ฒŒ ๋œ๋‹ค. ๊ณต์ฃผ๋‹˜์„ ๊ตฌ์ถœํ•˜๊ณ  ํ”„๋Ÿฌํฌ์ฆˆ ํ•˜๊ณ  ..

[c++]๋ฐฑ์ค€ 1260๋ฒˆ : DFS์™€ BFS
Algorithm ๋ฌธ์ œ/BOJ 2020. 3. 20. 20:33

๋ฌธ์ œ : ๋ฐฑ์ค€ 1260๋ฒˆ _ DFS์™€ BFS ์‹œ๊ฐ„ ์ œํ•œ ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ ์ œ์ถœ ์ •๋‹ต ๋งž์€ ์‚ฌ๋žŒ ์ •๋‹ต ๋น„์œจ 2 ์ดˆ 128 MB 87845 28912 16832 31.543% ๋ฌธ์ œ ๊ทธ๋ž˜ํ”„๋ฅผ DFS๋กœ ํƒ์ƒ‰ํ•œ ๊ฒฐ๊ณผ์™€ BFS๋กœ ํƒ์ƒ‰ํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋‹จ, ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ๋Š” ์ •์ ์ด ์—ฌ๋Ÿฌ ๊ฐœ์ธ ๊ฒฝ์šฐ์—๋Š” ์ •์  ๋ฒˆํ˜ธ๊ฐ€ ์ž‘์€ ๊ฒƒ์„ ๋จผ์ € ๋ฐฉ๋ฌธํ•˜๊ณ , ๋” ์ด์ƒ ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ๋Š” ์ ์ด ์—†๋Š” ๊ฒฝ์šฐ ์ข…๋ฃŒํ•œ๋‹ค. ์ •์  ๋ฒˆํ˜ธ๋Š” 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€์ด๋‹ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 1,000), ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ M(1 ≤ M ≤ 10,000), ํƒ์ƒ‰์„ ์‹œ์ž‘ํ•  ์ •์ ์˜ ๋ฒˆํ˜ธ V๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ„์„ ์ด ์—ฐ๊ฒฐํ•˜๋Š” ๋‘ ์ •์ ์˜ ๋ฒˆํ˜ธ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์–ด๋–ค ๋‘ ์ •์  ์‚ฌ์ด์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ„์„ ์ด ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ์ž…๋ ฅ์œผ๋กœ..

[python] ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ•ด๊ฒฐ ์ „๋žต 1๊ถŒ :: ํŒฌ๋ฏธํŒ… (ID: FANMEETING)
Algorithm ๋ฌธ์ œ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ•ด๊ฒฐ์ „๋žต 2020. 3. 16. 13:17

๋ฌธ์ œ ๊ฐ€์žฅ ๋ฉค๋ฒ„๊ฐ€ ๋งŽ์€ ์•„์ด๋Œ ๊ทธ๋ฃน์œผ๋กœ ๊ธฐ๋„ค์Šค ๋ถ์— ์˜ฌ๋ผ ์žˆ๋Š” ํ˜ผ์„ฑ ํŒ ๊ทธ๋ฃน ํ•˜์ดํผ์‹œ๋‹ˆ์–ด๊ฐ€ ๋ฐ๋ท” 10์ฃผ๋…„ ๊ธฐ๋… ํŒฌ ๋ฏธํŒ…์„ ๊ฐœ์ตœํ–ˆ์Šต๋‹ˆ๋‹ค. ํŒฌ ๋ฏธํŒ…์˜ ํ•œ ์ˆœ์„œ๋กœ, ๋ฉค๋ฒ„๋“ค๊ณผ ์ฐธ๊ฐ€ํ•œ ํŒฌ๋“ค์ด ํฌ์˜น์„ ํ•˜๋Š” ํ–‰์‚ฌ๋ฅผ ๊ฐ–๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ดํผ์‹œ๋‹ˆ์–ด์˜ ๋ฉค๋ฒ„๋“ค์€ ์šฐ์„  ๋ฌด๋Œ€์— ์ผ๋ ฌ๋กœ ์„ญ๋‹ˆ๋‹ค. ํŒฌ ๋ฏธํŒ…์— ์ฐธ๊ฐ€ํ•œ M๋ช…์˜ ํŒฌ๋“ค์€ ์ค„์„ ์„œ์„œ ๋งจ ์˜ค๋ฅธ์ชฝ ๋ฉค๋ฒ„์—์„œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด ํ•œ ๋ช…์”ฉ ์™ผ์ชฝ์œผ๋กœ ์›€์ง์ด๋ฉฐ ๋ฉค๋ฒ„๋“ค๊ณผ ํ•˜๋‚˜์”ฉ ํฌ์˜น์„ ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  ํŒฌ๋“ค์€ ๋™์‹œ์— ํ•œ ๋ช…์”ฉ ์›€์ง์ž…๋‹ˆ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ ํ–‰์‚ฌ ๊ณผ์ •์˜ ์ผ๋ถ€๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. a~d๋Š” ๋„ค ๋ช…์˜ ํ•˜์ดํผ์‹œ๋‹ˆ์–ด ๋ฉค๋ฒ„๋“ค์ด๊ณ , 0~5๋Š” ์—ฌ์„ฏ ๋ช…์˜ ํŒฌ๋“ค์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ•˜์ดํผ์‹œ๋‹ˆ์–ด์˜ ๋‚จ์„ฑ ๋ฉค๋ฒ„๋“ค์ด ๋‚จ์„ฑ ํŒฌ๊ณผ ํฌ์˜นํ•˜๊ธฐ๊ฐ€ ๋ฏผ๋งํ•˜๋‹ค๊ณ  ์—ฌ๊ฒจ์„œ, ๋‚จ์„ฑ ํŒฌ๊ณผ๋Š” ํฌ์˜น ๋Œ€์‹  ์•…์ˆ˜๋ฅผ ํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ค„์„ ์„  ๋ฉค๋ฒ„๋“ค๊ณผ ํŒฌ๋“ค..