Skip to content
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
44 changes: 44 additions & 0 deletions 11-Kruskal&Prim/jaehoon/11866_요세푸스문제0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int N,K;
queue<int> q;

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

cin >> N >> K;
for (int i = 1; i <= N; i++) {
q.push(i);
}

cout <<"<";
int num = 1;
while(!q.empty()){
if (num == K) {
if (q.size() == 1) {
cout << q.front();
}
else {
cout << q.front() << ", ";
}

q.pop();
num = 1;
continue;
}

int temp = q.front();
q.pop();
q.push(temp);
num++;
}
cout << ">";

return 0;
}
76 changes: 76 additions & 0 deletions 11-Kruskal&Prim/jaehoon/1192_네트워크 연결.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define MAX 1000+1
int V, E;
int parent[MAX];
vector<pair<int, pair<int, int>>> v;

int find(int x) { //해당 노드의 부모를 찾는 함수
if (x == parent[x]) {
return x;
}
else {
return parent[x] = find(parent[x]);
}
}

void Union(int x, int y) { //부모가 다르다면 도착 노드의 부모를 시작 노드로 지정하는 함수
x = find(x);
y = find(y);

if (x != y) {
parent[y] = x;
}
}

bool sameParent(int x, int y) { //부모가 같은지 판별하는 함수
x = find(x);
y = find(y);

if (x == y) {
return true;
}

else {
return false;
}
}

int main(void) {

ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);


int v1, v2, cost;
int result = 0;
cin >> V >> E;

for (int i = 0; i < E; i++) { //시작 노드, 도착 노드, 가중치 입력받기
cin >> v1 >> v2 >> cost;
v.push_back(make_pair(cost, make_pair(v1, v2)));
}
sort(v.begin(), v.end()); // 오름차순 정렬

for (int i = 1; i <= V; i++) { //부모의 초기 값은 자기 자신
parent[i] = i;
}

for (int i = 0; i < E; i++) { // 두 노드가 동일하지 않다면 둘을 이어주는 Union 함수 실행 후 가중치 더하기
int vertex1 = v[i].second.first;
int vertex2 = v[i].second.second;
if (!sameParent(vertex1, vertex2)) {
Union(vertex1, vertex2);
result += v[i].first;
}
}
cout << result << "\n";

return 0;
}
72 changes: 72 additions & 0 deletions 11-Kruskal&Prim/jaehoon/1197_최소 스패닝 트리.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define MAX 10000+1
int V, E;
int parent[MAX];
vector<pair<int, pair<int, int>>> v;

int find(int x) {
if (x == parent[x]) {
return x;
}
else {
return parent[x] = find(parent[x]);
}
}

void Union(int x, int y) {
x = find(x);
y = find(y);

if (x != y) {
parent[y] = x;
}
}

bool sameParent(int x, int y) {
x = find(x);
y = find(y);

if (x == y) {
return true;
}

else {
return false;
}
}

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

int v1, v2, cost;
int result = 0;
cin >> V >> E;

for (int i = 0; i < E; i++) { //시작 노드, 도착 노드, 가중치 입력받기
cin >> v1 >> v2 >> cost;
v.push_back(make_pair(cost, make_pair(v1, v2)));
}
sort(v.begin(), v.end()); // 오름차순 정렬

for (int i = 1; i <= V; i++) { //부모의 초기 값은 자기 자신
parent[i] = i;
}

for (int i = 0; i < E; i++) { // 두 노드가 동일하지 않다면 둘을 이어주는 Union 함수 실행 후 가중치 더하기
int vertex1 = v[i].second.first;
int vertex2 = v[i].second.second;
if (!sameParent(vertex1, vertex2)) {
Union(vertex1, vertex2);
result += v[i].first;
}
}
cout << result<<"\n";

return 0;
}
42 changes: 42 additions & 0 deletions 11-Kruskal&Prim/jaehoon/19598_최소 회의실 개수.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int>pil;

int N, start, e;
int cnt = 0, res = 0;
vector<pil> v;

int main(void) {

ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

cin >> N;
for (int i = 0; i < N; i++) { // 시작하는 시간은 1, 끝나는 시간은 -1로 vector에 삽입
cin >> start >> e;
v.push_back(make_pair(start, 1));
v.push_back(make_pair(e, -1));

}
sort(v.begin(), v.end()); //오름차순 정렬


for (int i = 0; i < v.size(); i++) {
if (v[i].second == 1) { //시작할 때 +1 끝날때 -1해서 최대값 구함
cnt++;
res = max(cnt, res);
}
else {
cnt--;
}
}

cout << res;


return 0;
}
File renamed without changes.