Skip to content

Commit fc7ffbb

Browse files
committed
[Update] folder name change
1 parent d44aa72 commit fc7ffbb

File tree

126 files changed

+7981
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+7981
-0
lines changed

Binary_search/BinarySearch.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#define NUMBER 12
3+
4+
using namespace std;
5+
6+
int a[] = { 1, 3, 5, 7, 9, 11, 14, 15, 18, 19, 25, 28 };
7+
int search_num = 7;
8+
9+
int search(int start, int end, int target) {
10+
if (start > end) return -1;
11+
12+
int mid = (start + end) / 2;
13+
14+
if (a[mid] == target) return mid;
15+
else if (a[mid] > target) return search(start, mid - 1, target);
16+
else return search(mid + 1, end, target);
17+
}
18+
19+
int main() {
20+
int result = search(0, NUMBER - 1, search_num);
21+
if (result != -1)
22+
cout << result + 1 << "¹øÂ°¿¡¼­ ã¾Ò½À´Ï´Ù.";
23+
return 0;
24+
}

Binary_search/LinearSearch.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#define NUMBER 10
3+
4+
using namespace std;
5+
6+
int a[] = { 8, 3, 4, 5, 1, 9, 6, 7, 2, 0 };
7+
int search = 7;
8+
9+
int main(void) {
10+
for (int i = 0; i < NUMBER; i++) {
11+
if (a[i] == search) {
12+
cout << i + 1 << "¹øÂ°¿¡¼­ ã¾Ò½À´Ï´Ù.";
13+
}
14+
}
15+
return 0;
16+
}

Brute_force/Brute_Force_LCS.cpp

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
5+
using namespace std;
6+
7+
// length of strX(m), strY(n)
8+
int n, m;
9+
// save the status of array
10+
int ch[10];
11+
// sequence X, Y
12+
string strX, strY;
13+
// get the subset of sequence (X or Y)
14+
vector<string> subSet;
15+
16+
/*
17+
function name : DFS
18+
brief : This function makes subset of sequence X
19+
if X's length is m, this function makes 2^m subsets
20+
argument :
21+
idx means the index of string
22+
XorY true = X, false = Y
23+
verbose true = print the subset string, false = print x
24+
return : void
25+
*/
26+
void DFS(int idx, bool XorY, bool verbose=false) {
27+
if (XorY) {
28+
// X is shorter than Y
29+
if (idx == m) {
30+
string str;
31+
for (int i = 0; i < m; i++) {
32+
if (ch[i] == 1)
33+
str += strX[i];
34+
}
35+
// push subset to subSet vector
36+
subSet.push_back(str);
37+
if(verbose)
38+
cout << str << endl;
39+
return;
40+
}
41+
else {
42+
// case1: ch[idx] = 1
43+
ch[idx] = 1;
44+
DFS(idx + 1, XorY);
45+
// case2: ch[idx] = 0
46+
ch[idx] = 0;
47+
DFS(idx + 1, XorY);
48+
return;
49+
}
50+
}
51+
else {
52+
// Y is shorter than X
53+
if (idx == n) {
54+
string str;
55+
for (int i = 0; i < n; i++) {
56+
if (ch[i] == 1)
57+
str += strY[i];
58+
}
59+
// push subset to subSet vector
60+
subSet.push_back(str);
61+
cout << str << endl;
62+
return;
63+
}
64+
else {
65+
// case1: ch[idx] = 1
66+
ch[idx] = 1;
67+
DFS(idx + 1, XorY);
68+
// case2: ch[idx] = 0
69+
ch[idx] = 0;
70+
DFS(idx + 1, XorY);
71+
return;
72+
}
73+
}
74+
}
75+
/*
76+
function name : getLCS
77+
brief : This function find the LCS of two sequences (X and Y)
78+
first calculate the maxLength(length of LCS) and
79+
find the LCS with maxLength and finally print the result(LCSs)
80+
return : void
81+
*/
82+
void getLCS(bool XorY, bool verbose=true) {
83+
int maxLength = 0;
84+
vector<string> result;
85+
string sequence;
86+
// select the string
87+
if (XorY) sequence = strY;
88+
else sequence = strX;
89+
90+
// get the length of LCS
91+
for (int i = 0; i < subSet.size(); i++) {
92+
string str = subSet[i];
93+
int idx = 0;
94+
// compare ith subset with strY (sequence Y)
95+
for (int j = 0; j < sequence.size(); j++) {
96+
if (sequence[j] == str[idx])
97+
idx++;
98+
}
99+
if (idx == str.length() && str.length() > maxLength) {
100+
maxLength = idx;
101+
}
102+
}
103+
// find the LCS with maxLength(length of LCS)
104+
for (int i = 0; i < subSet.size(); i++) {
105+
// skip the other case (not the LCS)
106+
if (subSet[i].length() != maxLength) continue;
107+
string str = subSet[i];
108+
int idx = 0;
109+
for (int j = 0; j < sequence.size(); j++) {
110+
if (sequence[j] == str[idx])
111+
idx++;
112+
}
113+
if (idx == str.length()) {
114+
result.push_back(str);
115+
}
116+
}
117+
118+
if (verbose) {
119+
cout << "LCS length : " << maxLength << endl;
120+
cout << "LCS : \n";
121+
for (int i = 0; i < result.size(); i++) {
122+
cout << result[i] << "\n";
123+
}
124+
}
125+
126+
return;
127+
}
128+
129+
int main() {
130+
bool XorY;
131+
cin >> strX >> strY;
132+
// get the length of strX and strY
133+
m = strX.length();
134+
n = strY.length();
135+
136+
// set the XorY(select the sequence to find subset)
137+
if (m > n)
138+
XorY = false; // we will find the subset of Y
139+
else
140+
XorY = true; // we will find the subset of X
141+
142+
// print the result
143+
cout << "### subset of X ###" << endl;
144+
// call DFS (get the subset of sequence)
145+
DFS(0, XorY);
146+
cout << "number of subset : " << subSet.size() << endl;
147+
// call getLCS (get the LSC of two sequences) and print LCSs
148+
getLCS(XorY);
149+
cout << "### end of program ###" << endl;
150+
return 0;
151+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Date: 2022/02/19
3+
Brief:
4+
simple brute force problem
5+
Reference:
6+
*/
7+
#include <iostream>
8+
#define MAX 10001
9+
10+
using namespace std;
11+
12+
int arr[MAX];
13+
14+
bool check(int x) {
15+
int cnt = 0;
16+
int num;
17+
while (1) {
18+
num = x % 10;
19+
x /= 10;
20+
if (num == 6) {
21+
cnt++;
22+
if (cnt == 3) {
23+
return true;
24+
}
25+
}
26+
else {
27+
cnt = 0;
28+
}
29+
if (x == 0) break;
30+
}
31+
32+
return false;
33+
}
34+
35+
int main() {
36+
int n, cnt = 0;
37+
cin.tie(NULL);
38+
39+
cin >> n;
40+
41+
for (int i = 1; ; i++) {
42+
if (check(i)) {
43+
arr[cnt++] = i;
44+
}
45+
if (cnt == 10000) break;
46+
}
47+
cout << arr[n - 1] << "\n";
48+
49+
return 0;
50+
}
51+
52+
/*
53+
규칙이 뒤죽박죽이여서 그냥
54+
가장 작은 수부터 확인하면서 666에 대한
55+
pattern matching이 가능한 프로그램을 구현해야
56+
될 것 같다는 생각이 듬. (brute force 방식으로)
57+
*/
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
Date: 2022/02/20
3+
Brief:
4+
simple brute-force problem
5+
Reference:
6+
https://velog.io/@skyepodium/%EB%B0%B1%EC%A4%80-14500-%ED%85%8C%ED%8A%B8%EB%A1%9C%EB%AF%B8%EB%85%B8
7+
*/
8+
#include <iostream>
9+
#define MAX 501
10+
11+
using namespace std;
12+
13+
int map[MAX][MAX];
14+
bool visited[MAX][MAX];
15+
int arrX[4] = { 0, 0, 1, -1 };
16+
int arrY[4] = { 1, -1, 0, 0 };
17+
int cur[5];
18+
int maxDistance = 0;
19+
20+
int n, m;
21+
22+
bool inRange(int x, int y) {
23+
if (x <= 0 || x > n || y <= 0 || y > m)
24+
return false;
25+
else
26+
return true;
27+
}
28+
29+
void checkingTetromino(int x, int y, int sum, int num) {
30+
if (num == 4) {
31+
// if current combination is bigger than current maxDistance
32+
if (sum > maxDistance) {
33+
maxDistance = sum;
34+
}
35+
return;
36+
}
37+
38+
for (int i = 0; i < 4; i++) {
39+
int nextX = x + arrX[i];
40+
int nextY = y + arrY[i];
41+
42+
if (!inRange(nextX, nextY))
43+
continue;
44+
45+
if (visited[nextX][nextY]) {
46+
continue;
47+
}
48+
else {
49+
visited[nextX][nextY] = true;
50+
checkingTetromino(nextX, nextY, sum + map[nextX][nextY], num + 1);
51+
visited[nextX][nextY] = false;
52+
}
53+
}
54+
return;
55+
}
56+
57+
void checkingParticular(int x, int y) {
58+
int sum = 0;
59+
// 1. ㅜ
60+
if (inRange(x, y + 1) && inRange(x, y + 2) && inRange(x + 1, y + 1)) {
61+
sum = (map[x][y] + map[x][y + 1] + map[x][y + 2] + map[x + 1][y + 1]);
62+
maxDistance = maxDistance > sum ? maxDistance : sum;
63+
}
64+
// 2. ㅏ
65+
if (inRange(x + 1, y) && inRange(x + 2, y) && inRange(x + 1, y + 1)) {
66+
sum = (map[x][y] + map[x + 1][y] + map[x + 2][y] + map[x + 1][y + 1]);
67+
maxDistance = maxDistance > sum ? maxDistance : sum;
68+
}
69+
// 3. ㅗ
70+
if (inRange(x, y + 1) && inRange(x - 1, y + 1) && inRange(x, y + 2)) {
71+
sum = (map[x][y] + map[x][y + 1] + map[x - 1][y + 1] + map[x][y + 2]);
72+
maxDistance = maxDistance > sum ? maxDistance : sum;
73+
}
74+
// 4. ㅓ
75+
if (inRange(x, y + 1) && inRange(x - 1, y + 1) && inRange(x + 1, y + 1)) {
76+
sum = (map[x][y] + map[x][y + 1] + map[x - 1][y + 1] + map[x + 1][y + 1]);
77+
maxDistance = maxDistance > sum ? maxDistance : sum;
78+
}
79+
return;
80+
}
81+
82+
int main() {
83+
int i, j;
84+
cin.tie(NULL);
85+
86+
cin >> n >> m;
87+
88+
for (i = 1; i <= n; i++) {
89+
for (j = 1; j <= m; j++) {
90+
cin >> map[i][j];
91+
}
92+
}
93+
94+
for (i = 1; i <= n; i++) {
95+
for (j = 1; j <= m; j++) {
96+
visited[i][j] = true;
97+
checkingTetromino(i, j, map[i][j], 1);
98+
visited[i][j] = false;
99+
checkingParticular(i, j);
100+
}
101+
}
102+
103+
cout << maxDistance << "\n";
104+
105+
106+
return 0;
107+
}
108+
109+
/*
110+
4개의 정사각형이 이어져있는 경우 -> 테트로미노라고 부른다.
111+
112+
주어진 맵에서 테트로미노 하나 놓았을 때, 최고점이 되는 경우의
113+
점수를 return하면 된다.
114+
115+
reference 참고해서 ㅗ, ㅜ, ㅓ, ㅏ case를 따로 살펴야 함을 알았다.
116+
*/

0 commit comments

Comments
 (0)