diff --git a/oesnuj/README.md b/oesnuj/README.md index a1d5c67..2513849 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -7,4 +7,9 @@ | 3차시 | 2024.04.02 | 덱 | [카드 놓기](https://www.acmicpc.net/problem/18115) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/11) | | 4차시 | 2024.04.06 | 스택 | [옥상 정원 꾸미기](https://www.acmicpc.net/problem/6198) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/14) | | 5차시 | 2024.04.13 | 이분탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) | +| 6차시 | 2024.05.06 | 기하학 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) | +| 7차시 | 2024.05.08 | 스택, 큐, 덱 | [queuestack](https://www.acmicpc.net/problem/24511) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/24) | +| 8차시 | 2024.05.13 | 우선순위 큐 | [카드 정렬하기](https://www.acmicpc.net/problem/1715) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/27) | +| 9차시 | 2024.05.30 | 구현 | [빙고](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) | +| 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) | --- diff --git "a/oesnuj/\352\265\254\355\230\204/21608.js" "b/oesnuj/\352\265\254\355\230\204/21608.js" new file mode 100644 index 0000000..6c471d4 --- /dev/null +++ "b/oesnuj/\352\265\254\355\230\204/21608.js" @@ -0,0 +1,78 @@ +const fs = require('fs'); +const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; +const input = fs.readFileSync(filepath).toString().trim().split('\n'); +//입력 데이터 정리 +const N = +input.shift(); +const students = input.map(x => { + const [num, ...likes] = x.trim().split(' ').map(Number); + return { num, likes }; +}); + +let board = Array.from({ length: N }, () => Array(N).fill(0)); + +const dr = [-1, 1, 0, 0]; +const dc = [0, 0, -1, 1]; + +main(); + +function main(){ + for(let i=0; i< N**2; i++){ + if(i == 0){ + board[1][1] = students[i].num; //첫학생은 1,1에 무조건 앉는다. + continue; + } + choiceSeat(students[i].num); //학생을 조건에 맞게 앉히기 + } + console.log(calcSatisfy()); //모두 앉은 후 만족도 계산하기 +} + +// 최적의 자리 선택 및 학생 배치 함수 +function choiceSeat(studentNum){ + const neighborInfos = []; //인접 자리 정보를 모으는 배열 + for(let i = 0; i { + if (a.match !== b.match) { + return b.match - a.match; // match 기준 내림차순 정렬 + } else if (a.empty !== b.empty) { + return b.empty - a.empty; // empty 기준 내림차순 정렬 + } else if (a.r !== b.r) { + return a.r - b.r; // r 기준 오름차순 정렬 + } else { + return a.c - b.c; // c 기준 오름차순 정렬 + } + }); + board[neighborInfos[0].r][neighborInfos[0].c] = studentNum; //최적의 위치에 앉히기 +} + +// 특정 자리의 인접 정보 계산 함수 +function getSeatInfo(r, c, studentNum){ + let empty = 0; + let match = 0; + // 학생 번호에 맞는 좋아하는 학생들 찾기 + let studentLikes = students.find(student => student.num === studentNum)?.likes || []; + for(let i = 0; i< 4; i++){ + nr = r + dr[i]; + nc= c + dc[i]; + if(nr < 0 || nc < 0 || nr >= N || nc >= N) continue; + if (board[nr][nc] == 0) empty++; + else if(studentLikes.includes(board[nr][nc])) match++ + } + return { r: r, c: c, empty: empty, match: match }; +} + +//만족도 처리 +function calcSatisfy(){ + let result = 0; + for(let i = 0; i +using namespace std; + +const int BINGO_SIZE = 5; +int board[BINGO_SIZE][BINGO_SIZE]; + +void changeBingo(int target); +int checkBingo(); + + + +int main() +{ + ios::sync_with_stdio(0); cin.tie(0); + for (int i = 0; i < BINGO_SIZE; i++) + { + for (int j = 0; j < BINGO_SIZE; j++) + { + cin >> board[i][j]; + } + } + + int sayCnt = 0; + for (int i = 0; i < BINGO_SIZE * BINGO_SIZE; i++) + { + int num; + cin >> num; + sayCnt++; + changeBingo(num); + if (checkBingo() >= 3) { + cout << sayCnt; + return 0; + } + } + return 0; +} + + +void changeBingo(int target) //사회자가 부른 수 체크하기 +{ + for (int i = 0; i < BINGO_SIZE; i++){ + for (int j = 0; j < BINGO_SIZE; j++){ + if (board[i][j] == target){ + board[i][j] = 0; + return; + } + } + } + return; +} + +int checkBingo() //현재 보드판에 빙고가 몇줄인지 +{ + int bingoCnt = 0; + + for (int i = 0; i < BINGO_SIZE; i++) //가로, 세로 빙고 확인 + { + int horizontal = 0, vertical = 0; + for (int j = 0; j < BINGO_SIZE; j++){ + if (!board[i][j]) + horizontal++; + if (!board[j][i]) + vertical++; + } + if (horizontal == BINGO_SIZE) bingoCnt++; + if (vertical == BINGO_SIZE) bingoCnt++; + } + + int right_diagonal = 0, left_diagonal = 0; + for (int i = 0; i < BINGO_SIZE; i++) //대각선 2개 빙고 확인 + { + if (!board[i][i]) right_diagonal++; + if (!board[i][BINGO_SIZE - i - 1]) left_diagonal++; + } + if (right_diagonal == BINGO_SIZE) bingoCnt++; + if (left_diagonal == BINGO_SIZE) bingoCnt++; + + return bingoCnt; +} \ No newline at end of file diff --git "a/oesnuj/\352\270\260\355\225\230/1485.cpp" "b/oesnuj/\352\270\260\355\225\230/1485.cpp" new file mode 100644 index 0000000..b795e78 --- /dev/null +++ "b/oesnuj/\352\270\260\355\225\230/1485.cpp" @@ -0,0 +1,53 @@ +#include +#include +#include +#include +using namespace std; + +struct Point +{ + int x, y; +}; + +int calcDistance(Point a, Point b) +{ + return pow(a.x - b.x, 2) + pow(a.y - b.y, 2); +} + +bool compareInfo(Point &a, Point &b) +{ + if(a.x == b.x) + return a.y < b.y; + return a.x < b.x; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); + + int n; + cin >> n; + + while (n--) + { + vector v(4); + for (int i = 0; i < 4; i++) { + cin >> v[i].x >> v[i].y; + } + sort(v.begin(), v.end(),compareInfo); + //2 3 + //0 1 + int s1 = calcDistance(v[0], v[1]); //선분 + int s2 = calcDistance(v[0], v[2]); + int s3 = calcDistance(v[1], v[3]); + int s4 = calcDistance(v[2], v[3]); + + int dia1 = calcDistance(v[0], v[3]); //대각선 + int dia2 = calcDistance(v[1], v[2]); + if (s1 == s2 && s2 == s3 && s3 == s4 && dia1 == dia2) //네변의 길이가 같고 대각선의 길이가 같다. + cout << 1 << '\n'; + else + cout << 0 << '\n'; + } + return 0; +} \ No newline at end of file diff --git "a/oesnuj/\353\215\261/24511.cpp" "b/oesnuj/\353\215\261/24511.cpp" new file mode 100644 index 0000000..1868b93 --- /dev/null +++ "b/oesnuj/\353\215\261/24511.cpp" @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +int main() +{ + ios::sync_with_stdio(false); cin.tie(NULL); + int n; + cin >> n; + vector dataStructure(n); //스텍인지 큐인지 입력받기 + for (auto& i : dataStructure){ + cin >> i; + } + + deque queuestack; + for (int i = 0; i < n; i++) + { + int x; + cin >> x; + if (dataStructure.at(i) == 0) //큐인 경우에만 처리, 스택은 무조건 입력값이 나오기에 없다고 보면됨 + queuestack.push_back(x); + } + int m; + cin >> m; + for (int i = 0; i < m; i++) + { + int x; + cin >> x; + queuestack.push_front(x); + cout << queuestack.back() << " "; + queuestack.pop_back(); + } + return 0; +} diff --git "a/oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" "b/oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" new file mode 100644 index 0000000..7311750 --- /dev/null +++ "b/oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" @@ -0,0 +1,33 @@ +#include +#include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); + + priority_queue , greater> pq; //최소 힙으로 우선순위 큐 선언 + int n; + cin >> n; + for (int i = 0; i < n; i++) //우선순위 큐에 다 넣음 + { + int x; + cin >> x; + pq.push(x); + } + int result = 0; + while(pq.size() > 1) //우선순위 큐에 값이 하나만 남을 때 까지 반복 + { + // 우선순위 큐에서 가장 작은 두 수를 꺼내서 합침 + int a = pq.top(); + pq.pop(); + int b = pq.top(); + pq.pop(); + int sum = a + b; + pq.push(sum); // 합친 결과를 우선순위 큐에 다시 넣음 + + result += sum; // 결과값을 누적 + } + cout << result; + return 0; +} \ No newline at end of file