diff --git "a/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\353\217\204\354\240\204/2343.cpp" "b/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\353\217\204\354\240\204/2343.cpp" new file mode 100644 index 00000000..32fbf262 --- /dev/null +++ "b/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\353\217\204\354\240\204/2343.cpp" @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +using namespace std; + +int cntBlu(int time, vector &lecture){ + int blu =0; //블루레이 갯수 + int sum = lecture[0]; // 한 블루레이에 저장되는 영상의 길이 합 + for(int i=1;i &lecture){ + while(left<=right){ + int mid = (left+right)/2; + int cnt = cntBlu(mid,lecture); + if(cnt >=target){ //블루레이의 갯수가 target보다 많다면 힌 블루레이의 크기를 늘려줌 + left = mid +1; + }else{ + right = mid - 1; + } + } + return left; + +} + +int main(){ + cin.tie(0); + cout.tie(0); + ios_base::sync_with_stdio(NULL); + int n,m; + cin >> n >>m; + vector lecture(n,0); + for(int i=0;i>lecture[i]; + } + + int sum = accumulate(lecture.begin(),lecture.end(),0); + + //최소는 영상의 최댓값, 최대는 영상의 전체 합 + cout << binarySearch(*max_element(lecture.begin(),lecture.end()),sum,m,lecture); + +} \ No newline at end of file diff --git "a/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\355\225\204\354\210\230/10815.cpp" "b/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\355\225\204\354\210\230/10815.cpp" new file mode 100644 index 00000000..d639f2a7 --- /dev/null +++ "b/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\355\225\204\354\210\230/10815.cpp" @@ -0,0 +1,41 @@ +#include +#include +#include + +using namespace std; + + +int binarySearch(int left, int right, int key,vector& card){ + while(left<=right){ + int mid =(left+right)/2; + if(card[mid] ==key){ + return 1; + } + else if(card[mid]>key){ + right = mid -1; + }else{ + left = mid+1; + } + } + return 0; +} + +int main(){ + cin.tie(0); + cout.tie(0); + ios_base::sync_with_stdio(NULL); + int n,m,key; + cin >>n; + vector card (n,0); + for(int i=0;i>card[i]; + } + sort(card.begin(),card.end()); + + cin >>m; + while(m--){ + cin >>key; + cout < +#include +#include + +using namespace std; + +vector>board; + +int ans; + +void dfs(int x, int y, int depth, int sum) { + + vector dx = { -1,0,1,0 }; //좌상우하, x축 방향으로의 움직임 + vector dy = { 0,1,0,-1 }; // y축 방향으로의 움직임 + + if (depth == 4) { // 칸 4개 선택했으면 ans 최대값 갱신 + ans = max(ans, sum); + return; + } + + // 아래 코드가 들어가면 가지치기가 돼 백트래킹이 돼요! + //if (ans >= MAX * (4 - cnt) + sum) { + // return; + //} + + for (int i = 0; i < 4; i++) { + // 선택할 칸 + int nx = x + dx[i]; //i가 0 이라면 x=x-1 y=y, i가 2 라면 x=x+1 y=y, + int ny = y + dy[i]; //i가 1이라면 x=x y=y+1, i가 4 라면 x=x y=y-1 + + if (nx < 0 || nx >= board.size() || ny < 0 || ny >= board[0].size() || !board[nx][ny]) { // 범위를 벗어났거나 이미 방문한 블록이라면 넘어가기 + continue; + } + + int temp = board[nx][ny]; // 방문 처리하기 전 해당 칸 가치 저장 + board[nx][ny] = 0; // 방문 처리 : 4개를 선택함에 있어서 똑같은 블록을 선택하지 않기 위해 + + // 다음 탐색 -> depth 1 증가 && sum값에 현재 칸 가치 더하기 + if (depth == 2) { // ㅜ 모양은 현재 위치에서 다시 탐색! + dfs(x, y, depth + 1, sum + temp); + } + dfs(nx, ny, depth + 1, sum + temp); // 선택한 칸으로 이동 + + board[nx][ny] = temp; // 이후의 케이스에서 재방문할 수 있으므로 원래대로 돌려줌 + + } +} + +/* +* HINT : 하나의 도형은 무언가 특별한 것 같아요! or 테트로미노의 모양은 탐색의 관점에서 특징이 있는 것 같아요! +* 1. ㅜ 모양을 제외한 테트로미노의 모양은 깊이가 4인 dfs의 탐색 모양 +* -> dfs로 블록을 하나씩 선택해가면서 개수(cnt)와 합(sum)을 계산 +* -> 4개 선택하면 최댓값 갱신 +* 2. 예외 : ㅜ 모양은 블록을 2개 선택했을 때 현재 블록에서 다시 블록을 선택해준다. +*/ + + +int main() { + + // 입력 + int n, m; //세로 n, 가로 m + cin >> n >> m; + board.assign(n, vector(m, 0)); //테트로미노를 놓을 종이 + + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> board[i][j]; //각 칸에 쓰여진 수 입력받기 + } + } + + // 연산 + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + int temp = board[i][j]; + board[i][j] = 0; //i,j 번째칸 방문했으므로 0 처리 + dfs(i, j, 1, temp); + board[i][j] = temp; //다시 방문할 수 있으므로 원래대로 되돌려놓음 + } + } + + // 출력 + cout << ans; + return 0; +} \ No newline at end of file diff --git "a/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\355\225\204\354\210\230/16401.cpp" "b/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\355\225\204\354\210\230/16401.cpp" new file mode 100644 index 00000000..19fa273b --- /dev/null +++ "b/10_\354\235\264\353\266\204 \355\203\220\354\203\211/\355\225\204\354\210\230/16401.cpp" @@ -0,0 +1,45 @@ +#include +#include +#include + +using namespace std; + +int lenSnack(int length,vector &l){ + int cnt =0; + for(int i=0;i=length){ + cnt+=l[i]/length; //한 개의 과자에서 여러 조각이 나올 수 있음. (과자의 길이 / 조각의 길이) + } + } + return cnt; +} + +int binarySearch(int left, int right, int target, vector& l){ + while(left<=right){ + int mid =(left+right)/2; + int num = lenSnack(mid,l); + if(num >=target){ //나눠진 과자의 갯수가 target보다 크다면 조각의 길이를 더 길게해 갯수를 줄일 수 있도록 함 + left = mid +1; + } + else{ + right = mid -1; + } + } + return left-1; +} + +int main(){ + int m,n; + cin >>m >> n; + vector l (n,0); + for(int i=0; i>l[i]; + } + + sort(l.begin(),l.end()); + + //조각의 최소 길이는 1 최대 길이는 l[n-1] + cout < + +using namespace std; + +const int SIZE = 50; //방 최대 크기 +const int CLEAN = 2; //청소상태는 2 +int n, m, cnt = 0; // 세로 크기, 가로 크기, 청소한 칸 개수 + +int board[SIZE][SIZE]; // (0: 빈 칸, 1: 벽, 2: 청소 완료) +int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; // 북 동 남 서 + +void dfs(int row, int col, int dir) { + // 1. 현재 위치 청소 + if(board[row][col] != CLEAN) { //현재 위치한 청소 되지 않았다면 + cnt++; //청소한 칸 +1 + } + board[row][col] = CLEAN; //해당 위치 청소 표시 + + // [현재 칸의 주변 4칸 중 청소되지 않은 빈 칸이 있는가] + // 3. 현재 칸의 주변 4칸 중 청소되지 않은 빈 칸이 있는 경우 + for(int i = 0; i < 4; i++) { // 3-1. 반시계 방향으로 90º 회전 + int new_dir = (dir-i+3) % 4; + int new_row = row + dy[new_dir], new_col = col + dx[new_dir]; //반시계 방향으로 회전한 후 전진했을 때 좌표 + + if(board[new_row][new_col] == 0) { // 3-2. 아직 청소되지 않은 빈 칸 발견 + dfs(new_row, new_col, new_dir); // 한 칸 전진 + return; + } + } + + // 2. 현재 칸의 주변 4칸 중 청소되지 않은 빈 칸이 없는 경우 + int back_dir = (dir+2) % 4; + int back_row = row + dy[back_dir], back_col = col + dx[back_dir]; //한 칸 후진했을 때 위치 + + // [바라보는 방향을 유지한 채로 한 칸 후진할 수 있는가] + // 2-2. 뒤쪽 칸이 벽이라 후진할 수 없는 경우 + if(board[back_row][back_col] == 1) { + return; //동작 멈춤 + } + // 2-1. 바라보는 방향을 유지한 채로 한 칸 후진 + dfs(back_row, back_col, dir); // 방향 유지한 상태로 후진 (2-3) + return; +} + +/* + * [로봇 청소기 작동] + * 1. 현재 칸이 아직 청소되지 않은 경우, 현재 칸을 청소한다. + * 2. 현재 칸의 주변 4칸 중 청소되지 않은 빈 칸이 없는 경우, + * 2-1. 바라보는 방향을 유지한 채로 한 칸 후진할 수 있다면 한 칸 후진하고 1번으로 돌아간다. + * 2-2. 바라보는 방향의 뒤쪽 칸이 벽이라 후진할 수 없다면 작동을 멈춘다. + * 3. 현재 칸의 주변 4칸 중 청소되지 않은 빈 칸이 있는 경우, + * 3-1. 반시계 방향으로 90º 회전한다. + * 3-2. 바라보는 방향을 기준으로 앞쪽 칸이 청소되지 않은 빈 칸인 경우 한 칸 전진한다. + * 3-3. 1번으로 돌아간다. +*/ + +int main() { + int r, c, d; // 로봇 청소기 정보 + + // 입력 + cin >> n >> m; //방의 크기 + cin >> r >> c >> d; //로봇 청소기 초기 위치, 바라보는 방향 + + for(int i = 0; i < n; i++) { //칸 상태 입력 + for(int j = 0; j < m; j++) { + cin >> board[i][j]; + } + } + + // 연산 & 출력 + dfs(r, c, d); + cout << cnt; + return 0; +} \ No newline at end of file diff --git "a/11_\355\210\254 \355\217\254\354\235\270\355\204\260/\355\225\204\354\210\230/20437.cpp" "b/11_\355\210\254 \355\217\254\354\235\270\355\204\260/\355\225\204\354\210\230/20437.cpp" new file mode 100644 index 00000000..2781889f --- /dev/null +++ "b/11_\355\210\254 \355\217\254\354\235\270\355\204\260/\355\225\204\354\210\230/20437.cpp" @@ -0,0 +1,53 @@ +#include +#include +#include +using namespace std; + +typedef pair ci; + + +ci containK(int k, string w, vector &al){ + int len,max_len=-1,min_len=10001; + + for (int i =0;i> t; + while(t--){ + vector al (26,0); + cin >>w >> k; + for (int i =0;i +#include + +using namespace std; + +int cntSubseq(int k,int n,vector &seq){ + int left =0, right =1; + int cnt =1; + int ans = cnt; + vector num (200001,0); + num[seq[left]]++; + while(right> n >>k; + vector seq(n,0); + + for( int i=0;i>seq[i]; + } + cout << cntSubseq(k,n,seq); + + + return 0; +}