반응형
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 | 29 |
30 | 31 |
Tags
- 자의식 해체
- 백준 파티
- 부동산기사읽기
- 부동산 기사읽기
- 경제금융용어
- 평균급여액
- 역행자
- 급여액
- 이중통화채(dual currency bond)
- 유전자오작동
- 업무지구별
- 정체성 만들기
- 자발적 실업
- 황농문 서울대교수
- 경제적 자유를 위한 5가지 공부법
- KFO
- 웅덩이 매매법
- 구해줘월부
- 제로금리정책
- 연방준비제도(FRS)/연방준비은행(FRB)
- 백준 1238
- 경제 기사읽기
- 월부TV
- 특수목적기구
- 한국직업개발원
- 행크TV
- 경제기사 읽기
- 매일경제
- 엥겔의법칙
- 원금리스크
Archives
- Today
- Total
록키의 No Pain, No Gain
[SWEA] 점심 식사시간 본문
반응형
조합, 우선순위 큐를 사용하여 풀었다.
주의해야 할 점은 조합을 구할 때 기저 값 넘겨주는 것
그리고 정확하게 진행되는 상황을 종이에 써서 명확히 이해하고 코딩할것 !!!!!!!!!!!!!
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#include <cstring>
#include <algorithm>
using namespace std;
int T, N, answer;
vector<pair<int, int>> peoples;
vector<pair<int, int>> stairs;
vector<int> dist[2];
vector<int> stairVal;
void solution(int selected) {
priority_queue<int> pq[2];
for (int i = 0; i < peoples.size(); i++) {
if (selected & (1 << i)) pq[0].push((-1) * dist[0][i]);
else pq[1].push((-1) * dist[1][i]);
}
int cnt[30];
memset(cnt, 0, sizeof(cnt));
int end1 = 0;
while (!pq[0].empty()) {
int d = pq[0].top()*(-1); pq[0].pop();
int count = 0;
int i = d + 2;
for (; count < stairVal[0]; i++) {
if (cnt[i] >= 3) continue;
count++;
cnt[i]++;
}
end1 = i;
}
memset(cnt, 0, sizeof(cnt));
int end2 = 0;
while (!pq[1].empty()) {
int d = pq[1].top() * (-1); pq[1].pop();
int count = 0;
int i = d + 2;
for (; count < stairVal[1]; i++) {
if (cnt[i] >= 3) continue;
count++;
cnt[i]++;
}
end2 = i;
}
answer = min(answer, max(end1, end2));
}
void combination(int n, int depth, int num, int selected) {
solution(selected);
for (int i = num; i < n; i++) {
combination(n, depth + 1, i + 1, selected | (1 << i));
}
}
int main() {
cin >> T;
for (int tc = 1; tc <= T; tc++) {
answer = 0x7fffffff;
peoples.clear(); stairs.clear(); dist[0].clear(); dist[1].clear(); stairVal.clear();
cin >> N;
int num;
for(int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
cin >> num;
if (num == 1) peoples.push_back({ i,j });
else if (num >= 2) {
stairVal.push_back(num);
stairs.push_back({ i,j });
}
}
//distance 계산
for (int i = 0; i < stairs.size(); i++) for(int j = 0; j < peoples.size(); j++) {
dist[i].push_back(abs(stairs[i].first - peoples[j].first) + abs(stairs[i].second - peoples[j].second));
}
combination(peoples.size() , 0, 0, 0);
cout << "#" << tc << " " << answer << "\n";
}
}
반응형
'알고리즘' 카테고리의 다른 글
[BOJ] 1238 파티 (0) | 2020.05.22 |
---|---|
[BOJ] 16235번 나무 재테크 (0) | 2020.05.21 |
[BOJ] 17471번 게리멘더링 (0) | 2020.04.28 |
[BOJ] 17822번 원판 돌리기 (0) | 2020.04.28 |
[BOJ] 17825 주사위 윷놀이 (0) | 2020.04.28 |
Comments