-
Notifications
You must be signed in to change notification settings - Fork 8
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
[김소희] 11주차 과제 제출합니다. #18
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||||
#include "bits/stdc++.h" | ||||||||||
|
||||||||||
using namespace std; | ||||||||||
//11578, 14497, 15976, 1953, 20313, 20955, 24391, 5859 | ||||||||||
vector<int> can_solve[11]; //index�� �л��� Ǯ �� �ִ� ���� | ||||||||||
vector<int> team; | ||||||||||
int problem, people, val, num, result = 11; | ||||||||||
|
||||||||||
void dfs(int cnt, int idx) { //������ ��� ��, ���� ��� | ||||||||||
if (cnt >= result) return; //���� ����� ������ ���� ���� ����� �ʿ��� ��� return | ||||||||||
if (cnt > 0) { | ||||||||||
bool solved[11] = { false, }; | ||||||||||
for (int i = 0; i < cnt; i++) { | ||||||||||
int cidx = team[i]; | ||||||||||
//���� ������ Ǯ �� �ִ� ���� �˻� | ||||||||||
for (int j = 0; j < can_solve[cidx].size(); j++) | ||||||||||
solved[can_solve[cidx][j]] = true; | ||||||||||
} | ||||||||||
bool avail = true; | ||||||||||
for (int i = 1; i <= problem; i++) { | ||||||||||
if (!solved[i]) { | ||||||||||
avail = false; | ||||||||||
break; | ||||||||||
} | ||||||||||
} | ||||||||||
//��� ������ Ǯ �� �ִٸ� �ּ� ���� ���� | ||||||||||
if (avail) | ||||||||||
result = min(result, cnt); | ||||||||||
} | ||||||||||
if (idx > people) return; | ||||||||||
for (int i = idx; i <= people; i++) { | ||||||||||
team.push_back(i); | ||||||||||
dfs(cnt + 1, i + 1); | ||||||||||
team.pop_back(); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
int main() { | ||||||||||
cin >> problem >> people; | ||||||||||
for (int i = 1; i <= people; i++) { | ||||||||||
cin >> val; | ||||||||||
for (int j = 0; j < val; j++) { | ||||||||||
cin >> num; | ||||||||||
can_solve[i].push_back(num); | ||||||||||
} | ||||||||||
} | ||||||||||
dfs(0, 1); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 소희님에게 이 문제가 어떤 부분에서 코드 작성이 어려웠는지 궁금합니다. |
||||||||||
if (result == 11) result = -1; | ||||||||||
cout << result; | ||||||||||
return 0; | ||||||||||
Comment on lines
+48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 삼항연산자 이용하는 방법도 존재합니다.
Suggested change
|
||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "bits/stdc++.h" | ||
|
||
using namespace std; | ||
// 14497, 15976, 1953, 20313, 20955, 24391, 5859 | ||
int n; | ||
vector<int> blue, white; | ||
|
||
|
||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(0); | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) | ||
{ | ||
int cnt; | ||
cin >> cnt; | ||
if (i == 1) { | ||
blue.push_back(i); | ||
for (int j = 0; j < cnt; j++) | ||
{ | ||
int s; | ||
cin >> s; | ||
} | ||
} | ||
else { | ||
int sum = 0; | ||
for (int j = 0; j < cnt; j++) | ||
{ | ||
int hate; | ||
cin >> hate; | ||
auto it1 = find(blue.begin(), blue.end(), hate); | ||
auto it2 = find(white.begin(), white.end(), hate); | ||
|
||
if (it1 == blue.end()&&sum==0) { | ||
blue.push_back(i); | ||
sum++; | ||
} | ||
if (it2 == white.end()&&sum==0) { | ||
white.push_back(i); | ||
sum++; | ||
} | ||
if(sum==0) | ||
blue.push_back(i); | ||
Comment on lines
+35
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 싫어하는 사람이 없는 사람이 일부 존재한다면 어떻게 될까요? |
||
|
||
|
||
} | ||
} | ||
} | ||
|
||
sort(blue.begin(), blue.end()); | ||
sort(white.begin(), white.end()); | ||
if (white.size() == 0) { | ||
blue.erase(blue.begin() + 1); | ||
white.push_back(1); | ||
}if (blue.size() == 0) { | ||
white.erase(white.begin() + 1); | ||
blue.push_back(1); | ||
} | ||
Comment on lines
+53
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필요한가요? |
||
cout << blue.size() << endl; | ||
for (int i = 0; i < blue.size(); i++) | ||
{ | ||
cout << blue.at(i) << " "; | ||
} | ||
cout << endl << white.size() << endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '\n' 쓰기 힘들거나 귀찮을 때
해놓으면 편리합니다. |
||
for (int i = 0; i < white.size(); i++) | ||
{ | ||
cout << white.at(i) << " "; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
,
없어도 모두 초기화됩니다