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

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค(Programmers)86

[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - [1์ฐจ] ์บ์‹œ(Level 2) ๋ฌธ์ œ 2022. 4. 7.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ํ”„๋ฆฐํ„ฐ(Level 2) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ”„๋ฆฐํ„ฐ ์ผ๋ฐ˜์ ์ธ ํ”„๋ฆฐํ„ฐ๋Š” ์ธ์‡„ ์š”์ฒญ์ด ๋“ค์–ด์˜จ ์ˆœ์„œ๋Œ€๋กœ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์ค‘์š”ํ•œ ๋ฌธ์„œ๊ฐ€ ๋‚˜์ค‘์— ์ธ์‡„๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด ์ค‘์š”๋„๊ฐ€ ๋†’์€ ๋ฌธ์„œ๋ฅผ ๋จผ์ € ์ธ์‡„ํ•˜๋Š” ํ”„๋ฆฐ programmers.co.kr ์ฝ”๋“œ // 01:19(๋ฌธ์ œ ์ดํ•ด ์‹œ์ž‘) // 01:27(๋ฌธ์ œ ๊ตฌํ˜„ ์‹œ์ž‘) ~ 01:44(ํ’€์ด ์™„๋ฃŒ) #include #include #include #include #include #include using namespace std; int solution(vector priorities, int location) { int answer = 0; mapdocs; queueq; for(int i=0; i 2022. 3. 23.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์‚ผ๊ฐ ๋‹ฌํŒฝ์ด(Level 2) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‚ผ๊ฐ ๋‹ฌํŒฝ์ด 5 [1,2,12,3,13,11,4,14,15,10,5,6,7,8,9] 6 [1,2,15,3,16,14,4,17,21,13,5,18,19,20,12,6,7,8,9,10,11] programmers.co.kr ์ฝ”๋“œ #include #include #include using namespace std; vector solution(int n) { vector answer; int num = 1; int move_cnt = n; int arr[1001][1001]={0,}; int x=0, y=0; for(int i=0; i 2022. 3. 14.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ํ”ผ๋กœ๋„(Level 2) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ”ผ๋กœ๋„ XX๊ฒŒ์ž„์—๋Š” ํ”ผ๋กœ๋„ ์‹œ์Šคํ…œ(0 ์ด์ƒ์˜ ์ •์ˆ˜๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค)์ด ์žˆ์œผ๋ฉฐ, ์ผ์ • ํ”ผ๋กœ๋„๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋˜์ „์„ ํƒํ—˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋•Œ, ๊ฐ ๋˜์ „๋งˆ๋‹ค ํƒํ—˜์„ ์‹œ์ž‘ํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ "์ตœ์†Œ ํ•„์š” ํ”ผ๋กœ๋„"์™€ ๋˜ programmers.co.kr ์ฝ”๋“œ #include #include #include using namespace std; int ans = 0; int backtracking(vector visited, int explore_cnt, int curr_point, vector& dungeons){ for(int i=0; i=need_point){ if(!visited[i]){ visited[i]=1; ans = max(ans, backtracking(visited, explore_.. 2022. 3. 4.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์˜์–ด ๋๋ง์ž‡๊ธฐ(Level 2) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์˜์–ด ๋๋ง์ž‡๊ธฐ 3 ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"] [3,3] 5 ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"] [0,0] programmers.co.kr ์ฝ”๋“œ #include #include #include #include using namespace std; vector solution(int n, vector words) { ve.. 2022. 3. 4.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์•ฝ์ˆ˜์˜ ๊ฐœ์ˆ˜์™€ ๋ง์…ˆ(Level 1) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์•ฝ์ˆ˜์˜ ๊ฐœ์ˆ˜์™€ ๋ง์…ˆ ๋‘ ์ •์ˆ˜ left์™€ right๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. left๋ถ€ํ„ฐ right๊นŒ์ง€์˜ ๋ชจ๋“  ์ˆ˜๋“ค ์ค‘์—์„œ, ์•ฝ์ˆ˜์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ง์ˆ˜์ธ ์ˆ˜๋Š” ๋”ํ•˜๊ณ , ์•ฝ์ˆ˜์˜ ๊ฐœ์ˆ˜๊ฐ€ ํ™€์ˆ˜์ธ ์ˆ˜๋Š” ๋บ€ ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ programmers.co.kr ์ฝ”๋“œ #include #include #include using namespace std; int solution(int left, int right) { int answer = 0; mapdivisor; for(int i=1; i 2022. 2. 13.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜( Level2) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜๋Š” F(0) = 0, F(1) = 1์ผ ๋•Œ, 1 ์ด์ƒ์˜ n์— ๋Œ€ํ•˜์—ฌ F(n) = F(n-1) + F(n-2) ๊ฐ€ ์ ์šฉ๋˜๋Š” ์ˆ˜ ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด F(2) = F(0) + F(1) = 0 + 1 = 1 F(3) = F(1) + F(2) = 1 + 1 = 2 F(4) = F(2) + F(3) = 1 + 2 = 3 F(5) = F(3) + F(4) = programmers.co.kr ์ฝ”๋“œ #include #include #define MOD 1234567 using namespace std; int dp[100001]; int solution(int n) { int answer = 0; dp[0]=0; dp[1]=1; for(int i=2; i 2021. 11. 8.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜( Level1) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ๋‘ ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ๋‘ ์ˆ˜์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด ๋ณด์„ธ์š”. ๋ฐฐ์—ด์˜ ๋งจ ์•ž์— ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜, ๊ทธ๋‹ค์Œ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋ฅผ ๋„ฃ์–ด ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‘ ์ˆ˜ 3, 12์˜ programmers.co.kr ์ฝ”๋“œ #include #include #include using namespace std; int gcd(int a,int b){ if(b==0) return a; else return gcd(b,a%b); } vector solution(int n, int m) { vector answer; int inp = gcd(n,m); answer.push_back(inp); answer.push_back(n*m/inp); retu.. 2021. 11. 8.
[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ๋ฐฐ๋‹ฌ( Level2) ๋ฌธ์ œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฐฐ๋‹ฌ 5 [[1,2,1],[2,3,3],[5,2,2],[1,4,2],[5,3,1],[5,4,2]] 3 4 6 [[1,2,1],[1,3,2],[2,3,2],[3,4,3],[3,5,2],[3,5,3],[5,6,1]] 4 4 programmers.co.kr ์ฝ”๋“œ #include #include #define INF 1e9 using namespace std; int solution(int N, vector road, int K) { int graph[51][51]={0, }; int answer = 0; vectormemory_city_cnt; for(int i=0; i 2021. 11. 8.