티스토리 뷰
https://www.acmicpc.net/problem/8982
8982번: 수족관 1
입력의 첫 줄은 수족관의 경계에 있는 꼭짓점의 개수 N(1 ≤ N ≤ 5,000)이 주어진다. N은 짝수이다. 수족관의 경계는 항상 꼭짓점 (0, 0)부터 시작한다. 그리고 마지막 꼭짓점은 (A, 0)의 형태로 끝난��
www.acmicpc.net
바닥면의 높이가 같은 인접 공간을 한 구역으로 묶어 풀이하였습니다.
C++ 소스 코드
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
n-=2;
n/=2;
vector<int> bottom(n,-1);
vector<int> holeIdx;
vector<int> top(n,0);
vector<int> width(n,0);
map<int, int> dict;
int x,y;
cin >> x >> y; // (0,0)
for(int i=0;i<n;i++){ // 수족관 경계
int x1,y1,x2,y2; // y1 == y2 짝으로 입력받음
cin >> x1 >> y1 >> x2 >> y2;
bottom[i]=y1;
width[i]=(x2-x1);
dict[x2]=i; // 구역 번호 = i
}
cin >> x >> y; // (x,0)
int m;
cin >> m;
for(int i=0;i<m;i++){ // 구멍 위치
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int index = dict[x2];
holeIdx.push_back(index);
}
for(int i=0;i<holeIdx.size();i++){
int idx = holeIdx[i];
int surface = bottom[idx];
for(int j=idx;j>=0;j--){
surface = min(surface, bottom[j]);
//높이 갱신
top[j] = max(top[j],surface);
}
surface = bottom[idx];
for(int j=idx+1;j<n;j++){
surface = min(surface, bottom[j]);
//높이 갱신
top[j] = max(top[j],surface);
}
}
long long ans = 0;
for(int i=0;i<n;i++){
if (bottom[i] > top[i]){
ans += (long long)(bottom[i]-top[i])*width[i];
}
}
cout << ans << '\n';
return 0;
}
'Algorithm > 알고리즘 문제풀이' 카테고리의 다른 글
프로그래머스) Lv1 - 키패드 누르기 [2020 카카오 인턴십] (0) | 2020.07.05 |
---|---|
BOJ) 1937 - 욕심쟁이 판다 (0) | 2020.07.01 |
BOJ) 3197 - 백조의 호수 (0) | 2020.06.30 |
BOJ) 2234 - 성곽 (0) | 2020.06.30 |
BOJ) 2422 - 한윤정이 이탈리아에 가서 아이스크림을 사먹는데 (0) | 2020.06.28 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- C++
- Lottie
- Reactivex
- infallible
- rxswift6
- blendshape
- Kotlin
- disposeBag
- GraphDB
- mergesort
- boj
- 카카오인턴십
- SWEA
- 백준
- 프로그래머스
- ios
- bounds
- Neo4j
- rxswift
- Swift
- 안드로이드
- 알고리즘
- ARKit
- blendshapes
- 백준온라인저지
- DispatchQueue
- coreml
- 코코아팟
- cocoapods
- SwiftUI
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
글 보관함