-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |