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
- 해시구현
- 시간 복잡도
- heap
- 원판 돌리기
- Stack 이란
- 백준 2447
- 풀이
- dfs
- 1764
- 버킷 정렬
- 해시 구현
- 백준 17822
- 백준 5397
- 백준 1406
- ㅣ풀이
- 자료구조
- qorwns
- 5397
- C/C++ 구현
- 백준
- 백준 17471
- 백준 1158
- 게리멘더링2
- AVL 시간 복잡도
- 백준 17779
- 별 찍기 10
- 조세퍼스 순열
- 스택의 특징
- 구현
- c#
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 10775] 공항 본문
https://www.acmicpc.net/problem/10775
1/6일 풀었던 문제
요구사항
1. 최대로 주차(?)할 수 있는 비행기 수 구하기
풀이
1. n번째가 차지하고 있으면 n-1번째가 비어있는가 검사한다.
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];
int parent[100001];
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);
if(x !=y){
if(x<y){
parent[y]=x;
}
else{
parent[x]=y;
}
}
}
int main()
{
int g,p;
cin>>g>>p;
for(int i=1 ; i <=g ; i++)
parent[i]=i;
int flag=0;
int ans=0;
for(int i=0 ; i < p ; i++){
int x;
scanf("%d",&x);
if(flag==1)
continue;
int gate=Find(x);
// cout<<"gate "<<gate<<endl;
if(gate==0){
flag=1;
// cout<<"parent "<< parent[x]<<endl;
//continue;
}
else{
ans++;
Union(gate,gate-1);
// cout<<"Union "<< parent[x]<<endl;
}
}
cout<<ans<<endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 2887] 행성 터널 (0) | 2020.01.09 |
---|---|
[백준 9938] 방 청소 (0) | 2020.01.09 |
[백준 10815] 숫자 카드 (0) | 2020.01.09 |
[백준 2805] 나무 자르기 (0) | 2020.01.08 |
[백준 1920] 수 찾기 (해시, 정렬) (2) | 2020.01.08 |
Comments