8000 0x13 · SungKweon/basic-algo-lecture@2b2e8e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b2e8e8

Browse files
committed
0x13
1 parent 1a7b3fa commit 2b2e8e8

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

0x13/10816.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// http://boj.kr/e78b47fa3e08436faada666bafcf9501
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int a[500005];
6+
int n;
7+
8+
int lower_idx(int target, int len){
9+
int st = 0;
10+
int en = len;
11+
while(st < en){
12+
int mid = (st+en)/2;
13+
if(a[mid] >= target) en = mid;
14+
else st = mid+1;
15+
}
16+
return st;
17+
}
18+
19+
int upper_idx(int target, int len){
20+
int st = 0;
21+
int en = len;
22+
while(st < en){
23+
int mid = (st+en)/2;
24+
if(a[mid] > target) en = mid;
25+
else st = mid+1;
26+
}
27+
return st;
28+
}
29+
30+
int main(void) {
31+
ios::sync_with_stdio(0);
32+
cin.tie(0);
33+
cin >> n;
34+
for(int i = 0; i < n; i++) cin >> a[i];
35+
sort(a,a+n);
36+
int m;
37+
cin >> m;
38+
while(m--){
39+
int t;
40+
cin >> t;
41+
cout << upper_idx(t,n)-lower_idx(t,n) << '\n';
42+
}
43+
}

0x13/10816_1.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// http://boj.kr/78ba45c70b3c4128ae11ded0b1015d71
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int a[500005];
6+
int n;
7+
8+
int main(void) {
9+
ios::sync_with_stdio(0);
10+
cin.tie(0);
11+
cin >> n;
12+
for(int i = 0; i < n; i++) cin >> a[i];
13+
sort(a,a+n);
14+
int m;
15+
cin >> m;
16+
while(m--){
17+
int t;
18+
cin >> t;
19+
cout << upper_bound(a,a+n,t)-lower_bound(a,a+n,t) << '\n';
20+
}
21+
}

0x13/1920_1.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// http://boj.kr/0d0917e336ac4d709029df43a9127ace
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
int a[100005];
5+
int n;
6+
7+
int main(void) {
8+
ios::sync_with_stdio(0);
9+
cin.tie(0);
10+
cin >> n;
11+
for(int i = 0; i < n; i++) cin >> a[i];
12+
sort(a,a+n);
13+
int m;
14+
cin >> m;
15+
while(m--){
16+
int t;
17+
cin >> t;
18+
cout << binary_search(a, a+n, t) << '\n';
19+
}
20+
}

0x13/2293.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// http://boj.kr/f19cd7f505434920a0a4a9aa86454364
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int n;
6+
int a[1005];
7+
vector<int> two;
8+
9+
int main(void) {
10+
ios::sync_with_stdio(0);
11+
cin.tie(0);
12+
cin >> n;
13+
for(int i = 0; i < n; i++) cin >> a[i];
14+
sort(a, a+n);
15+
for(int i = 0; i < n; i++){
16+
for(int j = i; j < n; j++)
17+
two.push_back(a[i]+a[j]);
18+
}
19+
sort(two.begin(), two.end());
20+
for(int i = n-1; i > 0; i--){
21+
for(int j = 0; j < i; j++){
22+
if(binary_search(two.begin(), two.end(), a[i]-a[j])){
23+
cout << a[i];
24+
return 0;
25+
}
26+
}
27+
}
28+
}

workbook/links.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
0x0F,정렬 II,https://www.acmicpc.net/workbook/view/7318
1717
0x10,다이나믹 프로그래밍,https://www.acmicpc.net/workbook/view/7319
1818
0x11,그리디,https://www.acmicpc.net/workbook/view/7320
19-
0x12,수학,https://www.acmicpc.net/workbook/view/8174
19+
0x12,수학,https://www.acmicpc.net/workbook/view/8174
20+
0x13,이분탐색,https://www.acmicpc.net/workbook/view/8400

0 commit comments

Comments
 (0)
0