Skip to content

Commit 289fd56

Browse files
committedSep 13, 2022
boj 2370 시장 선거 포스터
1 parent e0a7d1b commit 289fd56

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
 

‎좌표압축/2370.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#define MAX 20001
5+
using namespace std;
6+
typedef pair<int, int> pii;
7+
8+
vector<int> v;
9+
pii list[MAX];
10+
int cnt[MAX];
11+
int visit[MAX];
12+
int N;
13+
14+
void func() {
15+
sort(v.begin(), v.end());
16+
v.erase(unique(v.begin(), v.end()), v.end());
17+
18+
int num = 1;
19+
for (int i = 0; i < N; i++) {
20+
list[i] = { lower_bound(v.begin(), v.end(), list[i].first) - v.begin(), lower_bound(v.begin(), v.end(), list[i].second) - v.begin()};
21+
for (int j = list[i].first; j <= list[i].second; j++) {
22+
visit[j] = num;
23+
}
24+
num++;
25+
}
26+
27+
int ans = 0;
28+
int pre = -1;
29+
for (int i = 0; i < MAX; i++) {
30+
if (!visit[i]) continue;
31+
if (pre == -1 || (pre != visit[i] && !cnt[visit[i]])) {
32+
pre = visit[i];
33+
ans++;
34+
cnt[visit[i]]++;
35+
}
36+
}
37+
38+
cout << ans << '\n';
39+
}
40+
41+
void input() {
42+
cin >> N;
43+
for (int i = 0; i < N; i++) {
44+
cin >> list[i].first >> list[i].second;
45+
v.push_back(list[i].first);
46+
v.push_back(list[i].second);
47+
}
48+
}
49+
50+
int main() {
51+
cin.tie(NULL); cout.tie(NULL);
52+
ios::sync_with_stdio(false);
53+
54+
input();
55+
func();
56+
57+
return 0;
58+
}

0 commit comments

Comments
 (0)
Please sign in to comment.