Skip to content

Commit

Permalink
[week-11] 15686, 11000
Browse files Browse the repository at this point in the history
  • Loading branch information
wonkyDD committed Apr 2, 2024
1 parent 15c1a51 commit 06f55dd
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
Empty file removed week11/wonkyDD/.gitkeep
Empty file.
37 changes: 37 additions & 0 deletions week11/wonkyDD/11000.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
using pii = pair<int, int>;

int N;
vector<pii> v;
priority_queue<int, vector<int>, greater<int>> pq;

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

cin >> N;
int s,t;
for (int i=0; i<N; ++i) {
cin >> s >> t;
v.push_back({s, t});
}
// NOTE : 수업의 시작 시간을 기준으로 오름차순 정렬한다
sort(v.begin(), v.end());

// NOTE : 첫번째 수업은 강의실에 넣고 시작
pq.push(v[0].second);

for (int i=1; i<N; ++i) {
int t = pq.top();
// NOTE : 똑같은 강의실에 넣을 수 있다 (다음 수업 시작 시간 >= 현재 수업 끝나는 시간)
if (v[i].first >= t) pq.pop();
pq.push(v[i].second);
}

// NOTE : 큐에서 pop되지 못하고 남아있는 끝나는 시간 개수만큼 답이다
cout << pq.size();
return 0;
}
62 changes: 62 additions & 0 deletions week11/wonkyDD/15686.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
#define MAX 13
using pii = pair<int, int>;
struct pos {
int y; int x;
};
vector<pos> home, chicken;
vector<pos> choose;

bool check[MAX];

int N,M;
int ans = INT_MAX;

int dist(const pos& p1, const pos& p2) {
return abs(p1.y - p2.y) + abs(p1.x - p2.x);
}

int cal() {
int sum = 0;
for (int i=0; i<home.size(); ++i) {
int tmp = INT_MAX;
for (int j=0; j<choose.size(); ++j) {
tmp = min(tmp, dist(home[i], choose[j]));
}
sum += tmp;
}
return sum;
}

void dfs(int cur, int cnt) {
if (cnt == M) {
ans = min(ans, cal());
return;
}

for (int i=cur; i<chicken.size(); ++i) {
if (check[i]) continue;
choose.push_back(chicken[i]); check[i] = true;
dfs(i, cnt+1);
choose.pop_back(); check[i] = false;
}
}

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

cin >> N >> M;
for (int i=0; i<N; ++i) {
for (int j=0; j<N; ++j) {
int t; cin >> t;
if (t == 1) home.push_back({i, j});
else if (t == 2) chicken.push_back({i, j});
}
}
dfs(0, 0);
cout << ans;
return 0;
}

0 comments on commit 06f55dd

Please sign in to comment.