Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- ㅣ풀이
- Stack 이란
- 버킷 정렬
- heap
- 게리멘더링2
- dfs
- 1764
- 구현
- 풀이
- c#
- 백준 17822
- 백준 17471
- 5397
- 조세퍼스 순열
- 스택의 특징
- C/C++ 구현
- 백준 17779
- 별 찍기 10
- 해시 구현
- AVL 시간 복잡도
- 백준 1158
- 시간 복잡도
- 원판 돌리기
- qorwns
- 백준
- 백준 5397
- 해시구현
- 백준 1406
- 자료구조
- 백준 2447
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 9938] 방 청소 본문
https://www.acmicpc.net/problem/9938
1/6일날 풀었던 문제
요구사항
1. 빈 서랍에 술을 저장할 수 있나 없나에 대해 답을 하는 문제
풀이
1. 주어지는 입력을 통로라고 생각하고 하나로 쭉 이어준다
2. 적합한 자료구조인 Union-Find 사용한다.
#include <stdio.h>
#include <algorithm>
#include <list>
#include <iostream>
using namespace std;
struct NODE {
int prev;
int next;
int val;
};
const int PN=23;
const int SIZE=100000;
int table[100001];
bool visit[300001];
int parent[300001];
int Find(int x)
{
if(parent[x]==x) return x;
return parent[x]=Find(parent[x]);
}
void Union(int x, int y)
{
x = Find(x);
y = Find(y);
parent[x]=y;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=1; i <=m ; i++){
parent[i]=i;
}
for(int i=1 ; i <= n ; i++){
int x,y;
scanf("%d%d",&x,&y);
if(!visit[x]){
visit[x]=true;
Union(x,y);
printf("LADICA\n");
}
else if(!visit[y]){
visit[y]=true;
Union(y,x);
printf("LADICA\n");
}
else if(!visit[Find(x)]){
visit[Find(x)]=true;
Union(x,y);
printf("LADICA\n");
}
else if(!visit[Find(y)]){
visit[Find(y)]=true;
Union(y,x);
printf("LADICA\n");
}
else{
printf("SMECE\n");
}
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 1181] 단어 정렬 (0) | 2020.01.09 |
---|---|
[백준 2887] 행성 터널 (0) | 2020.01.09 |
[백준 10775] 공항 (0) | 2020.01.09 |
[백준 10815] 숫자 카드 (0) | 2020.01.09 |
[백준 2805] 나무 자르기 (0) | 2020.01.08 |
Comments