Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10-oesnuj #34

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
78 changes: 78 additions & 0 deletions oesnuj/๊ตฌํ˜„/21608.js
Original file line number Diff line number Diff line change
@@ -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<N; i++){
for(let j =0; j<N; j++){
if(board[i][j] !== 0) continue; //์ด๋ฏธ ์ฐจ์žˆ๋Š” ์ž๋ฆฌ ํŒจ์Šค
neighborInfos.push(getSeatInfo(i, j, studentNum));
}
}
neighborInfos.sort((a, b) => {
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<N; i++){ //๋‚จ์•„์žˆ๋Š” ๋ชจ๋“  ์ž๋ฆฌ์˜ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘
for(let j =0; j<N; j++){
result += Math.floor(10 ** (getSeatInfo(i, j ,board[i][j]).match-1));
}
}
return result;
}
์ถœ์ฒ˜: https://oesnuj.tistory.com/entry/Nodejs-๋ฐฑ์ค€-Javascript-21608-์ƒ์–ด-์ดˆ๋“ฑํ•™๊ต [๋น„ํŠธ๋กœ ๊ทธ๋ฆฌ๋Š” ์„ฑ์žฅ์ผ๊ธฐ:ํ‹ฐ์Šคํ† ๋ฆฌ]
79 changes: 79 additions & 0 deletions oesnuj/๊ตฌํ˜„/2578.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <iostream>
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;
}
53 changes: 53 additions & 0 deletions oesnuj/๊ธฐํ•˜/1485.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
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 <Point> 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;
}
35 changes: 35 additions & 0 deletions oesnuj/๋ฑ/24511.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <deque>
#include <vector>
using namespace std;

int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int n;
cin >> n;
vector <int> dataStructure(n); //์Šคํ…์ธ์ง€ ํ์ธ์ง€ ์ž…๋ ฅ๋ฐ›๊ธฐ
for (auto& i : dataStructure){
cin >> i;
}

deque <int> 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;
}
33 changes: 33 additions & 0 deletions oesnuj/์šฐ์„ ์ˆœ์œ„ ํ/1715.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <queue>

using namespace std;

int main() {
ios::sync_with_stdio(false); cin.tie(NULL);

priority_queue <int, vector<int>, greater<int>> 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;
}