Skip to content

Commit 46bab83

Browse files
authored
1 parent 35006c7 commit 46bab83

3 files changed

Lines changed: 191 additions & 0 deletions

File tree

2025-09-12/유현아/[BOJ]1182.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
5+
int N, S, cnt = 0;
6+
vector<int> arr;
7+
8+
void dfs(int idx, int sum) {
9+
if (idx == N) {
10+
if (sum == S) cnt++;
11+
return;
12+
}
13+
14+
// 현재 원소를 포함하는 경우
15+
dfs(idx + 1, sum + arr[idx]);
16+
// 현재 원소를 포함하지 않는 경우
17+
dfs(idx + 1, sum);
18+
}
19+
20+
int main() {
21+
freopen_s(new FILE*, "input.txt", "r", stdin);
22+
ios::sync_with_stdio(false);
23+
cin.tie(nullptr);
24+
25+
cin >> N >> S;
26+
arr.resize(N);
27+
for (int i = 0; i < N; i++) cin >> arr[i];
28+
29+
dfs(0, 0);
30+
31+
// 공집합은 제외해야 함 (S=0일 때 공집합이 카운트됨)
32+
if (S == 0) cnt--;
33+
34+
cout << cnt;
35+
return 0;
36+
}

2025-09-12/유현아/[BOJ]2116.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
5+
using namespace std;
6+
vector<vector<int>> dices;
7+
8+
int findingM(int dindex, int underIndex) {
9+
priority_queue<int> atleast2;
10+
11+
if (underIndex == 0 || underIndex == 5) {
12+
for (int j = 0; j < 6; j++) {
13+
if (j != 0 && j != 5)
14+
atleast2.push(dices[dindex][j]);
15+
}
16+
}
17+
else if (underIndex == 1 || underIndex == 3) {
18+
for (int j = 0; j < 6; j++) {
19+
if (j != 1 && j != 3)
20+
atleast2.push(dices[dindex][j]);
21+
}
22+
23+
}
24+
else if (underIndex == 2 || underIndex == 4) {
25+
for (int j = 0; j < 6; j++) {
26+
if (j != 2 && j != 4)
27+
atleast2.push(dices[dindex][j]);
28+
}
29+
}
30+
31+
32+
33+
return atleast2.top();
34+
}
35+
36+
37+
38+
int main() {
39+
freopen_s(new FILE*, "input.txt", "r", stdin);
40+
ios::sync_with_stdio(false);
41+
cin.tie(nullptr);
42+
int cnt;
43+
cin >> cnt;
44+
dices.assign(cnt, vector<int>(6,0));
45+
46+
for (int i = 0; i < cnt; i++) {
47+
for (int j = 0; j < 6; j++) {
48+
cin >> dices[i][j];
49+
}
50+
}
51+
52+
53+
54+
priority_queue<int> asf;
55+
56+
for (int i = 0; i < 6; i++) {
57+
priority_queue<int> atleast;
58+
59+
if (i == 0 || i == 5) {
60+
for (int j = 0; j < 6; j++) {
61+
if(j != 0 && j != 5 )
62+
atleast.push(dices[0][j]);
63+
}
64+
}
65+
else if (i == 1 || i == 3) {
66+
for (int j = 0; j < 6; j++) {
67+
if (j != 1 && j != 3)
68+
atleast.push(dices[0][j]);
69+
}
70+
71+
}
72+
else if (i == 2 || i == 4) {
73+
for (int j = 0; j < 6; j++) {
74+
if (j != 2 && j != 4)
75+
atleast.push(dices[0][j]);
76+
}
77+
}
78+
79+
int mmmax = atleast.top(), temp=0;
80+
int nextUnder = dices[0][i]; // 1번의 맨 위 숫자, 현재의 top, 다음의 under
81+
82+
for (int l = 0; l < 4; l++)
83+
{
84+
atleast.pop();
85+
}
86+
87+
88+
89+
for (int k = 1; k < cnt; k++) {
90+
for (int j = 0; j < 6; j++) {
91+
if (dices[k][j] == nextUnder) {
92+
temp = findingM(k, j);
93+
94+
if (k == cnt-1) continue;
95+
if (j == 0) nextUnder = dices[k][5];
96+
else if (j == 1) nextUnder = dices[k][3];
97+
else if (j == 2) nextUnder = dices[k][4];
98+
else if (j == 3) nextUnder = dices[k][1];
99+
else if (j == 4) nextUnder = dices[k][2];
100+
else if (j == 5) nextUnder = dices[k][0];
101+
102+
break;
103+
}
104+
}
105+
mmmax += temp;
106+
}
107+
108+
asf.push(mmmax);
109+
}
110+
111+
112+
cout << asf.top();
113+
114+
return 0;
115+
}

2025-09-12/유현아/[BOJ]2805.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int main() {
7+
freopen_s(new FILE*, "input.txt", "r", stdin);
8+
ios::sync_with_stdio(false);
9+
cin.tie(nullptr);
10+
11+
long long N, M;
12+
cin >> N >> M;
13+
vector<long long> tree(N);
14+
15+
for (long long& h : tree) cin >> h;
16+
17+
long long left = 0;
18+
long long right = *max_element(tree.begin(), tree.end());
19+
long long answer = 0;
20+
21+
while (left <= right) {
22+
long long mid = (left + right) / 2;
23+
long long sum = 0;
24+
25+
for (long long h : tree) {
26+
if (h > mid) sum += (h - mid);
27+
}
28+
29+
if (sum >= M) { // 조건 만족 → 더 높게 자를 수 있음
30+
answer = mid;
31+
left = mid + 1;
32+
}
33+
else { // 조건 불만족 → 더 낮게 잘라야 함
34+
right = mid - 1;
35+
}
36+
}
37+
38+
cout << answer;
39+
return 0;
40+
}

0 commit comments

Comments
 (0)