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

[김소희] 11주차 과제 제출합니다. #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions 5월9일/11578/11578_cpp_김소희.cpp
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, };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,없어도 모두 초기화됩니다

Suggested change
bool solved[11] = { false, };
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);
Copy link
Owner

Choose a reason for hiding this comment

The 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삼항연산자 이용하는 방법도 존재합니다.

Suggested change
if (result == 11) result = -1;
cout << result;
return 0;
cout << (result==11 ? -1 : result);

}
71 changes: 71 additions & 0 deletions 5월9일/1953/1953_cpp_김소희.cpp
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
Copy link
Owner

Choose a reason for hiding this comment

The 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
Copy link
Owner

Choose a reason for hiding this comment

The 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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endl 상당히 느리니까 주의하세요~

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'\n' 쓰기 힘들거나 귀찮을 때

#define endl '\n'

해놓으면 편리합니다.

for (int i = 0; i < white.size(); i++)
{
cout << white.at(i) << " ";
}

}