diff --git "a/09_\353\260\261\355\212\270\353\236\230\355\202\271/14888.cpp" "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/14888.cpp" new file mode 100644 index 0000000..1e522d6 --- /dev/null +++ "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/14888.cpp" @@ -0,0 +1,87 @@ +#include +#include + +using namespace std; +const int PLUS = 1; +const int MINUS = 2; +const int MULTIPLE = 3; +const int DIVISION = 4; +const int MAX_N = 11; +const int MAX_OPER = 5; + +int n; +int a[MAX_N]; +int oper[MAX_OPER]; //1번 인덱스 = 덧셈, 2번 인덱스 = 뺄셈, 3번 인덱스 = 곱셈, 4번 인덱스 = 나눗셈 + +int max_num = -1000000000; //최대 10억, 최소 -10억 +int min_num = 1000000000; + +//수식을 계산하는 함수 +int calculate(int oper, int result, int cnt) { + + if (oper == PLUS) { + result += a[cnt + 1]; + } + else if (oper == MINUS) { + result -= a[cnt + 1]; + } + else if (oper == MULTIPLE) { + result *= a[cnt + 1]; + } + else { //나눗셈 + result /= a[cnt + 1]; + } + + return result; +} + +//최댓값, 최소값을 갱신하는 함수 +void updateAns(int new_result) { + max_num = max(max_num, new_result); + min_num = min(min_num, new_result); +} + +//수식을 만드는 함수 +void makeExpression(int result, int cnt) { + + //기저 조건: n-1개의 연산자를 모두 사용한 경우 + if (cnt == n - 1) { + updateAns(result); + return; + } + + for (int i = 1; i <= 4; i++) { + if (oper[i] > 0) { //해당 연산자 사용횟수가 남은 경우에만 + oper[i]--; //연산자 사용 체크 + int new_result = calculate(i, result, cnt); + + makeExpression(new_result, cnt + 1); + + //돌려놓기 + oper[i]++; + } + } +} + +int main() { + + //입력 + cin >> n; + + for (int i = 0; i < n; i++) { + cin >> a[i]; //수열 a + } + + oper[0] = 0; + for (int i = 1; i < MAX_OPER; i++) { + cin >> oper[i]; //연산자 저장 + } + + //연산 + makeExpression(a[0], 0); //result 초기값: 첫 번째 숫자 + + //출력 + cout << max_num << "\n" << min_num; + + return 0; +} \ No newline at end of file diff --git "a/09_\353\260\261\355\212\270\353\236\230\355\202\271/15665.cpp" "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/15665.cpp" new file mode 100644 index 0000000..80046d9 --- /dev/null +++ "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/15665.cpp" @@ -0,0 +1,52 @@ +#include +#include +#include + +using namespace std; +const int MAX_N_M = 7; +const int MAX_NUM = 10000; + +int n, m; +set num_s; //자동으로 사전순 정렬 +vector sequence(MAX_N_M, 0); + +//수열 출력하는 함수 +void printSequence() { + for (int i = 0; i < m; i++) { + cout << sequence[i] << " "; + } + cout << "\n"; + return; +} + +//중복 수열 만드는 함수 +void getSequence(int cnt) { + + //기저 조건: M개의 숫자를 모두 뽑은 경우 + if (cnt == m) { + printSequence(); + return; + } + + for (set::iterator iter = num_s.begin(); iter != num_s.end(); iter++) { //set 순회는 iter 사용 + sequence[cnt] = *iter; + getSequence(cnt + 1); + } +} + +int main() { + + int num; + + //입력 + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> num; + num_s.insert(num); + } + + //연산 & 출력 + getSequence(0); + + return 0; +} \ No newline at end of file diff --git "a/09_\353\260\261\355\212\270\353\236\230\355\202\271/20055.cpp" "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/20055.cpp" new file mode 100644 index 0000000..ea7a9e1 --- /dev/null +++ "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/20055.cpp" @@ -0,0 +1,91 @@ +#include +#include + +using namespace std; + +struct info { //내구도와 로봇 존재 여부를 struct으로 관리 + int power; //내구도 변수 + bool is_on; //로봇의 존재 여부 변수 +}; + +//벨트를 한 칸 회전시키는 함수 +void rotateBelt(deque& belt, int n) { + belt.push_front(belt.back()); //가장 마지막 원소를 가장 앞에 놓으면 회전한 것과 같음 + belt.pop_back(); //가장 마지막 원소 삭제 + belt[n - 1].is_on = false; //로봇이 내리는 위치(n-1)에서 무조건 내림 +} + +//로봇을 한 칸 이동시키는 함수 +void moveRobot(deque& belt, int n) { + for (int i = n - 2; i >= 0; i--) { //0 ~ n-2까지만 체크하면 됨(n-1은 내리는 위치) + if (!belt[i].is_on) { //해당 칸에 로봇이 없으면 다음으로 + continue; + } + + //해당 칸에 로봇이 있을 때 + if (!belt[i + 1].is_on && (belt[i + 1].power >= 1)) { //다음 칸에 로봇이 없고, 내구도가 1 이상 남아 있다면 이동 + belt[i].is_on = false; //원래 있던 칸에서 이동하므로 false로 체크 + belt[i + 1].is_on = true; //이동할 칸(다음 칸) true로 체크 + belt[i + 1].power--; //이동할 칸(다음 칸) 내구도 1 감소 + } + + belt[n - 1].is_on = false; //로봇이 내리는 위치(n-1)이면 무조건 내림 + } +} + +//올리는 칸에 로봇을 올리는 함수 +void putRobot(deque& belt) { + if (!belt[0].is_on && belt[0].power >= 1) { //올리는 칸(0)에 로봇이 없고, 내구도가 1 이상 남아 있다면 로봇을 새로 올림 + belt[0].is_on = true; //올리는 칸(0) true로 체크 + belt[0].power--; //올리는 칸(0) 내구도 1 감소 + } +} + +//벨트의 내구도를 체크하는 함수 +bool checkFinish(deque& belt, int n, int k) { + int count = 0; //count를 0으로 초기화 + + for (int i = 0; i < 2 * n; i++) { //0부터 2n-1까지 벨트 전체를 돌면서 + if (belt[i].power == 0) { //해당 칸의 내구도가 0이면 + count++; //count값 +1 + } + } + + return count >= k; //count값이 주어진 k개 이상이면 true 반환 +} + +//1 ~ 3번 과정을 진행하고, 과정이 종료되었을 때 진행 중이었던 단계를 반환하는 함수 +int solution(deque& belt, int n, int k) { + int step = 1; //step을 1로 초기화 + while (true) { //if문에 걸릴 때까지 반복 + //벨트 회전시키기 + rotateBelt(belt, n); + //로봇 이동시키기 + moveRobot(belt, n); + //로봇 올리기 + putRobot(belt); + + //벨트 내구도 체크하기 + if (checkFinish(belt, n, k)) { //내구도가 0인 칸의 개수가 k개 이상이어서 true가 반환된 경우 + return step; //과정 종료, 그 때의 step을 반환 + } + step++; //문제의 1 ~ 3번까지 완료했으므로 step + 1 + } +} + +int main() { + //입력 + int n, k; + cin >> n >> k; //벨트의 길이와 종료 조건(내구도 0인 칸의 개수 조건) 입력 + deque belt(2 * n); //컨베이어 벨트의 내구도와 로봇 존재 여부 저장 + for (int i = 0; i < 2 * n; i++) { + cin >> belt[i].power; //2n개의 벨트 내구도 입력 + belt[i].is_on = false; //로봇 존재 여부 false로 초기화 + } + + //연산 + int answer = solution(belt, n, k); //answer에 과정이 종료되었을 때의 단계가 담김 + + //출력 + cout << answer; //answer 출력 +} \ No newline at end of file diff --git "a/09_\353\260\261\355\212\270\353\236\230\355\202\271/2477.cpp" "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/2477.cpp" new file mode 100644 index 0000000..825dee1 --- /dev/null +++ "b/09_\353\260\261\355\212\270\353\236\230\355\202\271/2477.cpp" @@ -0,0 +1,79 @@ +/* 푸는 중 */ +#include +#include + +using namespace std; +const int EAST = 1; +const int WEST = 2; +const int SOUTH = 3; +const int NORTH = 4; +const int SIDE_NUM = 6; +typedef pair ii; + +int calNumOfKMelon(vector side, int k) { + + //폭, 높이의 최댓값 구하기 + int max_width = 0; + int max_height = 0; + + for (int i = 0; i < SIDE_NUM; i++) { + if (side[i].first == EAST || side[i].first == WEST) { + max_width = max(max_width, side[i].second); + } + else { //side[i], first == SOUTH || side[i], first == NORTH + max_height = max(max_height, side[i].second); + } + } + + int area = max_height * max_width; //직사각형 넓이를 우선적으로 계산 + + int sub = 0; + if (side[1].second < side[5].second) { //2번째 동쪽으로의 길이가 6번째 서쪽으로의 길이보다 작은 경우 (ㄱ 또는┏) + if (side[0].second < side[4].second) { //1번째 남쪽으로의 길이가 5번째 북쪽으로의 길이보다 작은 경우(ㄱ) + sub = side[1].second * side[2].second; + } + else { //1번째 남쪽으로의 길이가 5번째 북쪽으로의 길이보다 큰 경우(┏) + sub = side[2].second * side[3].second; + } + } + else { //2번째 동쪽으로의 길이가 6번째 서쪽으로의 길이보다 큰 경우 (┗ 또는 ┛) + if (side[0].second < side[2].second) { //1번째 남쪽으로의 길이가 3번째 북쪽으로의 길이보다 작은 경우(┛) + sub = side[4].second * side[5].second; + } + else { //1번째 남쪽으로의 길이가 3번째 북쪽으로의 길이보다 큰 경우(┗) + sub = side[3].second * side[4].second; + } + } + + if (side[i].first == EAST) { + + } + + switch (side[i].first) { + case 1: + } + + area -= sub; //빈 네모 넓이 제외 + + return area * k; //참외의 총 개수 반환 +} + +int main() { + + int k; + int direction, length; + vector side(SIDE_NUM); + + //입력 + cin >> k; + for (int i = 0; i < SIDE_NUM; i++) { + cin >> direction >> length; + side[i].first = direction; + side[i].second = length; + } + + //연산 & 출력 + cout << calNumOfKMelon(side, k); + + return 0; +} \ No newline at end of file diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" new file mode 100644 index 0000000..64fcf9c --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" @@ -0,0 +1,55 @@ +#include +#include +#include + +using namespace std; + +int binarySearch(int n, int key_num, vector& card_num) { + + int left = 0; + int right = n - 1; + int mid; + + while (left <= right) { + mid = (left + right) / 2; + + if (card_num[mid] == key_num) { // ī ش ϸ 1 ȯ + return 1; + } + else if (card_num[mid] > key_num) { //( ) Ž + right = mid - 1; + } + else { //( ū ) Ž + left = mid + 1; + } + } + + return 0; // 0 ȯ +} + +int main() { + + ios_base::sync_with_stdio(NULL); + cin.tie(0); cout.tie(0); + + int n, m; + int key_num; + + //Է + cin >> n; + vector card_num(n); + for (int i = 0; i < n; i++) { + cin >> card_num[i]; + } + + sort(card_num.begin(), card_num.end()); // + + cin >> m; + while(m--) { + cin >> key_num; + // & + cout << binarySearch(n, key_num, card_num) << " "; + } + + return 0; +} \ No newline at end of file diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" new file mode 100644 index 0000000..9acbbf0 --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" @@ -0,0 +1,76 @@ +#include +#include +#include + +using namespace std; + +//ִ ̰ 'length' ǵ ڸ , ڸ ī +int cntNephew(int length, vector& snack) { + + int cnt = 0; //cnt 0 ʱȭ + + for (int i = 0; i < snack.size(); i++) { + if (snack[i] >= length) { + int tmp = snack[i] / length; //ڸ ɰ Ƿ + cnt += tmp; + } + } + + return cnt; +} + +int binarySearch(int n, int m, vector& snack) { + + int left = 1; + int right = snack.back(); //1 ~ ־ ̱ Ž + int mid; + + while (left <= right) { + mid = (left + right) / 2; + + int distributed = cntNephew(mid, snack); + + if (distributed >= m) { // ī(m) ڸ -> ̸ ÷ Ž + left = mid + 1; + } + else { // ī(m) ڸ -> ̸ ٿ Ž + right = mid - 1; + } + } + + // + int sum = 0; + for (int i = 0; i < snack.size(); i++) { + sum += snack[i]; + } + + if (sum < m) { // ī ڸ 0 ȯ + return 0; + } + else { + return left - 1; //Ž upper bound 1 + } +} + +int main() { + + ios_base::sync_with_stdio(NULL); + cin.tie(0); cout.tie(0); + + int m, n; + + //Է + cin >> m >> n; + + vector snack(n); + for (int i = 0; i < n; i++) { + cin >> snack[i]; + } + + sort(snack.begin(), snack.end()); // + + // & + cout << binarySearch(n, m, snack); + + return 0; +} \ No newline at end of file diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/17266.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/17266.cpp" new file mode 100644 index 0000000..2e032fd --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/17266.cpp" @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +using namespace std; + +int streetLamp(int n, int m, vector x) { + + int x_size = x.size(); + + int max_distance = max((x[1] - x[0]), (x[x_size - 1] - x[x_size - 2])); + + for (int i = 1; i < x_size - 2; i++) { + + int tmp_distance = ceil(double((x[i + 1] - x[i])) / 2); ////ε Ȧ ݿø ʿ + + max_distance = max(max_distance, tmp_distance); //ε ִ + } + + return max_distance; //ε ִ ε ּڰ +} + +int main() { + + int n, m; // ٸ , ε + vector x; //ġ ִ ε ġ + int x_tmp; + + //Է + cin >> n; + cin >> m; + + x.push_back(0); + for (int i = 1; i <= m; i++) { + cin >> x_tmp; + x.push_back(x_tmp); + } + x.push_back(n); + + // & + cout << streetLamp(n, m, x); + + return 0; +} \ No newline at end of file