'분류 전체보기'에 해당되는 글 84건
- 2020.06.03 :: [BOJ/1377] 버블 소트
- 2020.06.02 :: [BOJ/11004] K번째 수
- 2020.06.01 :: [BOJ/11652] 카드
- 2020.05.26 :: [BOJ/10989] 수 정렬하기 3
- 2020.05.24 :: [BOJ/10825] 국영수
- 2020.05.22 :: [BOJ/10814] 나이순 정렬
- 2020.05.21 :: [BOJ/11651] 좌표 정렬하기 2
- 2020.05.19 :: [BOJ/11650] 좌표 정렬하기
- 2020.05.18 :: [BOJ/2751] 수 정렬하기 2
- 2020.05.17 :: [BOJ/2004] 조합 0의 개수
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/1377
사용 알고리즘
- 정렬
풀이
- Bubble Sort를 1회 수행 시, 숫자가 앞으로 1칸 밖에 이동하지 못함
- 따라서 앞으로 가장 많이 이동한 칸의 수 + 1
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/1377.cpp
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector<pair<int, int>> a(n); for (int i = 0; i < n; ++i) { cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end()); int ans = -1; for (int i = 0; i < n; ++i) { if (ans < (a[i].second - i)) ans = a[i].second - i; } cout << ans + 1 << "\n"; return 0; } | cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/11004] K번째 수 (0) | 2020.06.02 |
---|---|
[BOJ/11652] 카드 (0) | 2020.06.01 |
[BOJ/10989] 수 정렬하기 3 (0) | 2020.05.26 |
[BOJ/10825] 국영수 (0) | 2020.05.24 |
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/11004
사용 알고리즘
- 정렬
풀이
- STL nth_element 이용
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/11004.cpp
#include <cstdio> #include <algorithm> using namespace std; int arr[5000003]; int main(void) { int n, k; scanf("%d %d", &n, &k); --k; for (int i = 0; i < n; ++i) scanf("%d", &arr[i]); nth_element(arr, arr + k, arr + n); printf("%d\n", arr[k]); return 0; } | cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/1377] 버블 소트 (0) | 2020.06.03 |
---|---|
[BOJ/11652] 카드 (0) | 2020.06.01 |
[BOJ/10989] 수 정렬하기 3 (0) | 2020.05.26 |
[BOJ/10825] 국영수 (0) | 2020.05.24 |
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/11652
사용 알고리즘
- 정렬
풀이
- 정렬 후 앞에서부터 인접한 수를 비교하며 개수를 셈
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/11652.cpp
#include <cstdio>
#include <algorithm>
using namespace std;
long long arr[100003];
int main(void) {
int n; scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%lld", &arr[i]);
sort(arr, arr + n);
int ansCount = 1, tempCount = 1;
long long ans = arr[0];
for (int i = 1; i < n; ++i) {
if (arr[i] == arr[i - 1]) {
++tempCount;
}
else {
if (ansCount < tempCount) {
ans = arr[i - 1];
ansCount = tempCount;
}
tempCount = 1;
}
}
if (ansCount < tempCount) ans = arr[n - 1];
printf("%lld\n", ans);
return 0;
}
|
cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/1377] 버블 소트 (0) | 2020.06.03 |
---|---|
[BOJ/11004] K번째 수 (0) | 2020.06.02 |
[BOJ/10989] 수 정렬하기 3 (0) | 2020.05.26 |
[BOJ/10825] 국영수 (0) | 2020.05.24 |
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/10989
사용 알고리즘
-
풀이
- 수의 개수를 세는 배열을 만들고, 해당 수의 개수만큼 출력
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/10989.cpp
#include <cstdio>
int cnt[10003];
int main(void) {
int n; for (scanf("%d", &n); n--;) {
int num; scanf("%d", &num);
++cnt[num];
}
for (int i = 1; i <= 10000; ++i) {
while (cnt[i]) {
printf("%d\n", i);
--cnt[i];
}
}
return 0;
}
|
cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/11004] K번째 수 (0) | 2020.06.02 |
---|---|
[BOJ/11652] 카드 (0) | 2020.06.01 |
[BOJ/10825] 국영수 (0) | 2020.05.24 |
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
[BOJ/11651] 좌표 정렬하기 2 (0) | 2020.05.21 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/10825
사용 알고리즘
- 정렬
풀이
- STL의 tuple 이용
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/10825.cpp
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
struct Person {
string name;
int kor;
int eng;
int math;
};
bool cmp(const Person& u, const Person& v) {
return make_tuple(-u.kor, u.eng, -u.math, u.name) < make_tuple(-v.kor, v.eng, -v.math, v.name);
}
int main(void) {
cin.tie(0); ios_base::sync_with_stdio(false);
int n; cin >> n;
vector<Person> p(n);
for (int i = 0; i < n; ++i) cin >> p[i].name >> p[i].kor >> p[i].eng >> p[i].math;
sort(p.begin(), p.end(), cmp);
for (int i = 0; i < n; ++i) cout << p[i].name << '\n';
return 0;
}
|
cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/11652] 카드 (0) | 2020.06.01 |
---|---|
[BOJ/10989] 수 정렬하기 3 (0) | 2020.05.26 |
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
[BOJ/11651] 좌표 정렬하기 2 (0) | 2020.05.21 |
[BOJ/11650] 좌표 정렬하기 (0) | 2020.05.19 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/10814
사용 알고리즘
- 정렬
풀이
- STL의 stable_sort 이용
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/10814.cpp
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; bool cmp(const pair<int, string> &u, const pair<int, string> &v) { return u.first < v.first; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector<pair<int, string>> v(n); for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second; stable_sort(v.begin(), v.end(), cmp); for (int i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << "\n"; return 0; } | cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/10989] 수 정렬하기 3 (0) | 2020.05.26 |
---|---|
[BOJ/10825] 국영수 (0) | 2020.05.24 |
[BOJ/11651] 좌표 정렬하기 2 (0) | 2020.05.21 |
[BOJ/11650] 좌표 정렬하기 (0) | 2020.05.19 |
[BOJ/2751] 수 정렬하기 2 (0) | 2020.05.18 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/11651
사용 알고리즘
- 정렬
풀이
-
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/11651.cpp
#include <cstdio> #include <vector> #include <algorithm> using namespace std; bool cmp(const pair<int, int> &u, const pair<int, int> &v) { if (u.second < v.second) return true; else if (u.second == v.second) return u.first < v.first; else return false; } int main(void) { int n; scanf("%d", &n); vector<pair<int, int>> v(n); for (int i = 0; i < n; ++i) scanf("%d %d", &v[i].first, &v[i].second); sort(v.begin(), v.end(), cmp); for (int i = 0; i < n; ++i) printf("%d %d\n", v[i].first, v[i].second); return 0; } | cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/10825] 국영수 (0) | 2020.05.24 |
---|---|
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
[BOJ/11650] 좌표 정렬하기 (0) | 2020.05.19 |
[BOJ/2751] 수 정렬하기 2 (0) | 2020.05.18 |
[BOJ/2004] 조합 0의 개수 (0) | 2020.05.17 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/11650
사용 알고리즘
- 정렬
풀이
-
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/11650.cpp
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<pair<int, int>> v;
int main(void) {
int n; scanf("%d", &n);
for (int i = 0; i < n; ++i) {
pair<int, int> p;
scanf("%d %d", &p.first, &p.second);
v.push_back(p);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; ++i) printf("%d %d\n", v[i].first, v[i].second);
return 0;
}
|
cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/10814] 나이순 정렬 (0) | 2020.05.22 |
---|---|
[BOJ/11651] 좌표 정렬하기 2 (0) | 2020.05.21 |
[BOJ/2751] 수 정렬하기 2 (0) | 2020.05.18 |
[BOJ/2004] 조합 0의 개수 (0) | 2020.05.17 |
[BOJ/1676] 팩토리얼 0의 개수 (0) | 2020.05.17 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/2751
사용 알고리즘
- 정렬
풀이
-
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/2751.cpp
#include <cstdio> #include <algorithm> using namespace std; int arr[1000003]; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &arr[i]); sort(arr, arr + n); for (int i = 0; i < n; ++i) printf("%d\n", arr[i]); return 0; } | cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/11651] 좌표 정렬하기 2 (0) | 2020.05.21 |
---|---|
[BOJ/11650] 좌표 정렬하기 (0) | 2020.05.19 |
[BOJ/2004] 조합 0의 개수 (0) | 2020.05.17 |
[BOJ/1676] 팩토리얼 0의 개수 (0) | 2020.05.17 |
[BOJ/10872] 팩토리얼 (0) | 2020.05.16 |
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/2004
사용 알고리즘
-
풀이
- 끝자리가 0이 되려면 2와 5가 필요
- 따라서 0이 몇 개인지 알아내려면, N!를 소인수 분해하여 2와 5의 개수중 작은 수의 개수가 0의 개수
- 2의 개수 = n / 2^1 + n / 2^2 + n / 2^3...
- 5의 개수 = n / 5^1 + n / 5^2 + n / 5^3...
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/2004.cpp
#include <cstdio>
#include <vector>
using namespace std;
int main(void) {
long long n, m; scanf("%lld %lld", &n, &m);
long long two = 0, five = 0;
for (long long i = 2; i <= n; i *= 2) two += (n / i);
for (long long i = 5; i <= n; i *= 5) five += (n / i);
for (long long i = 2; i <= m; i *= 2) two -= (m / i);
for (long long i = 5; i <= m; i *= 5) five -= (m / i);
for (long long i = 2; i <= (n - m); i *= 2) two -= ((n - m )/ i);
for (long long i = 5; i <= (n - m); i *= 5) five -= ((n - m) / i);
printf("%lld\n", (five < two) ? five : two);
return 0;
}
|
cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/11650] 좌표 정렬하기 (0) | 2020.05.19 |
---|---|
[BOJ/2751] 수 정렬하기 2 (0) | 2020.05.18 |
[BOJ/1676] 팩토리얼 0의 개수 (0) | 2020.05.17 |
[BOJ/10872] 팩토리얼 (0) | 2020.05.16 |
[BOJ/11653] 소인수분해 (0) | 2020.05.16 |