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

๐“ก๐“ธ๐“ธ๐“ถ๐Ÿฃ: ๐’œ๐“๐‘”๐‘œ๐“‡๐’พ๐“‰๐’ฝ๐“‚

(34)
BOJ1003: ํ”ผ๋ณด๋‚˜์น˜ ํ•จ์ˆ˜(Silver 3) #include #include #include #include long long fibo0[41] = { 0, }; long long fibo1[41] = { 0, }; void fibonacci(int n) { fibo0[0] = 1; fibo0[1] = 0; fibo1[0] = 0; fibo1[1] = 1; for (int i = 2; i
BOJ1016 : ์ œ๊ณฑใ„ดใ„ด์ˆ˜ (Gold 1) #include #include #include using namespace std; int save[1000001] = { 0, }; void checkfunc(unsigned long long start, unsigned long long end) { int a = end - start; for (unsigned long long i = 2; i max; checkfunc(min, max); for (int i = 0; i
BOJ1759: ์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ(Gold 5) #include #include #include #include using namespace std; bool checkfun(char *a, int L); void permu(char *a, char *target, int start, int level, int L, int C); bool compare(char a, char b) { return int(a) > L >> C; for (int i = 0; i > alphabet[i]; sort(alphabet, alphabet + C, compare); char result[30] = { ""}; //fo..
BOJ5576: ์ฝ˜ํ…Œ์ŠคํŠธ (Bronze 2) #include #include #include using namespace std; int main() { int Wnum[10], Knum[10]; for (int i = 0; i > Wnum[i]; } for (int i = 0; i > Knum[i]; } sort(Wnum, Wnum + 10); sort(Knum, Knum + 10); int Wmax = 0, Kmax = 0; for (int i = 9; i >= 7; i--) { Wmax += Wnum[i]; Kmax += Knum[i]; } cout
BOJ2628 : ์ข…์ด์ž๋ฅด๊ธฐ (Silver 5) #include #include #include #include using namespace std; int main() { int a, b; int linenum; int line_a[10000] = { 0, }; int line_b[10000] = { 0, }; int acount = 0, bcount = 0; int tmp = 0; cin >> a >> b; cin >> linenum; for (int i = 0; i > tmp; if (tmp == 1) { cin >> line_a[acount]; acount++; } else { cin >> line_b[bcount]; bcount++; } } // cout
BOJ2456 : ๋‚˜๋Š” ํ•™๊ธ‰ํšŒ์žฅ์ด๋‹ค (Bronze1) #include #include #include #include using namespace std; int main() { int N; int score[1000][3]; cin >> N; int total[3][3] = {0}; for (int i = 0; i > score[i][0] >> score[i][1] >> score[i][2]; if (score[i][0] == 1) total[0][0]++; if (score[i][0] == 2) total[0][1]++; if (score[i][0] == 3) total[0][2]++; if (score[i][1] == 1) total[1][0]++; if (score[i][1] == 2) total[1][1]++; if ..
[ALPS Study] DFS(๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰) - ๋‹จ์ง€๋ฒˆํ˜ธ๋ถ™์ด๊ธฐ(BOJ 2667) ์‚ฌ์‹ค ๋‚˜ ๋ฌธ์ œ ์ œ๋Œ€๋กœ ์ฝ์ง€๋„ ์•Š๊ณ  dfs ๋ฌธ์ œ ์•„๋ฌด๊ฑฐ๋‚˜ ์ฐ์–ด์„œ ํ’€๋ ค๊ณ  ์˜ฌ๋ ค๋†“๊ณ  ์ฝ์–ด๋ณด๋‹ˆ๊นŒ ์ €๋ฒˆ ๋ฌธ์ œ๋ž‘ ๊ฑฐ์˜ ๊ทธ๋ƒฅ ์™„๋ฒฝํžˆ ๊ฐ™์€..๋ฌธ์ œ์˜€๋‹ค..ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ์™œ ํ•œ ๊ฑฐ ์ง€...? ๋‹ค๋ฅธ ์ ์ด ์žˆ๋‹ค๋ฉด ๊ฐ ๋‹จ์ง€๋‚ด ์ง‘์˜ ์ˆ˜๋ฅผ ์ •๋ ฌํ•ด์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค๋Š”๊ฑฐ..?? #define _CRT_SECURE_NO_WARNINGS #include int map[50][50] = { 0, }; int count[50] = { 0, }; int M, N, K; int cnt = 0; int end = 0; int baechu = 0; void func(); void dfs(int x, int y); void printmap(); int main() { int T; int i; scanf("%d", &T); for (i = 0; i..
[ALPS Study] DFS(๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰) - ์œ ๊ธฐ๋†๋ฐฐ์ถ”(BOJ 1012) ์ž ์ด๋ฒˆ์—” ๋ฐ”๋กœ ํ’€์ง€ ์•Š๊ณ  ์–ด๋–ป๊ฒŒ ํ’€์–ด์•ผ ํ•  ์ง€ ์ƒ๊ฐํ•ด๋ณด๊ณ  ํ’€์–ด์•ผ๊ฒ ๋‹ค. ์‚ฌ์‹ค ๋‚œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€ ๋•Œ ์•ž ๋’ค ์•ˆ๊ฐ€๋ฆฌ๊ณ  ๋ฌด์ž‘์ • ์ฝ”๋“œ์งœ๋Š” ๋ฒ„๋ฆ‡์ด ์žˆ๋Š”๋ฐ ์•ˆ ์ข‹์€..๋ฒ„๋ฆ‡์ด๋‹ค.. ์šฐ์„ ์€ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›๊ณ  ์ž…๋ ฅ๋ฐ›์€๋งŒํผ ํ•จ์ˆ˜๋ฅผ ๋ฐ˜๋ณตํ•ด ์ค„ ๊ฒƒ์ด๋‹ค. int main() { int T; int i; scanf("%d", &T); for (i = 0; i < T; i++) { func(); } } ๋Œ€์ถฉ ๋ญ ์ด๋Ÿฐ์‹์œผ๋กœ! ๊ทธ๋Ÿฐ ๋‹ค์Œ์— ์ด์ œ ๋ชจ๋“ ! ์ฒ˜๋ฆฌ๋Š” func() ์ด๋ผ๋Š” ํ•จ์ˆ˜์—์„œ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. ์šฐ์„  M, N, K๋ฅผ ์ž…๋ ฅ๋ฐ›์•„์•ผ๊ฒ ์ง€? ๊ทธ๋ฆฌ๊ณ  map์ •๋ณด๋ฅผ ์ €์žฅํ•  map[50][50]์ด๋ผ๋Š” ๋ฐฐ์—ด๋„ ์„ ์–ธํ•ด์•ผ ํ•  ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ์— ์ด์ œ K๋ฒˆ๋งŒํผ for๋ฌธ์„ ๋Œ๋ ค์„œ ๋ฐฐ์ถ”์˜ ์œ„์น˜๋ฅผ map์— ์ €์žฅํ•  ๊ฒƒ์ด๋‹ค. void func..
[ALPS Study] DFS(๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰) - ํ…€ ํ”„๋กœ์ ํŠธ(BOJ 9466) - BOJ 9466 ํ…€ ํ”„๋กœ์ ํŠธ #define _CRT_SECURE_NO_WARNINGS #include int stu[1000][100000] = { 0 }; int visit[100000] = { 0 }; int main() { int i, T; scanf("%d", &T); for (i = 0; i < T; i++){ scan(i); } for (i = 0; i < T; i++){ dfs(i, 1); } } void scan(int i) { int j, N; scanf("%d", &N); for (j = 0; j < N; j++) { scanf("%d", &stu[i][j]); } } void dfs(int i, int s) { if (visit[s] == 0) visit[s] = 1; if (vi..
[ALPS Study] ํƒ์ƒ‰ -๊ทธ๋ž˜ํ”„์™€ DFS(๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰)(2) *C++์— ์žˆ๋Š” ์œ ์šฉํ•œ STL #include // vector : T type data๋ฅผ containํ•˜๋Š”, ํฌ๊ธฐ๊ฐ€ ์ •ํ•ด์ง€์ง€ ์•Š์€ ๋ฐฐ์—ด vector name; //์ด์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์„ ์–ธ name.begin() //์‹œ์ž‘ iterator(์ฃผ์†Œ ๊ฐœ๋…) ๋ฐ˜ํ™˜ name.end() //๋ iterator(๋ ์ฃผ์†Œ+1) ๋ฐ˜ํ™˜ name.size() // name์— ๋“ค์–ด์žˆ๋Š” ์›์†Œ์˜ ์ˆ˜ ๋ฐ˜ํ™˜ name.resize(int a, T b) //name์˜ ํฌ๊ธฐ๋ฅผ a๋กœ ์กฐ์ •, ๋นˆ ์นธ์€ b๋กœ ์ดˆ๊ธฐํ™”(b ์ƒ๋žต ๊ฐ€๋Šฅ, 0์œผ๋กœ ์ดˆ๊ธฐํ™”) name.empty() //name์ด ๋น„์—ˆ๋‹ค๋ฉด true, ์›์†Œ๊ฐ€ ์žˆ๋‹ค๋ฉด false ๋ฐ˜ํ™˜ name[i] //name์˜ i๋ฒˆ์งธ ์›์†Œ์— ์ ‘๊ทผ name.front() // name์˜ ์ฒซ๋ฒˆ์งธ ์›์†Œ์— ์ ‘..