Algorithm(218)
-
[BOJ] 2910번 : 빈도 정렬
1. problem : https://www.acmicpc.net/problem/2910 2. solution 1 :#include using namespace std;vector> nums; // {숫자, 순서, 빈도} 초기값 {0,0,0}int n, c; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> c; for (int i = 0; i > x; auto it = find_if(nums.begin(), nums.end(), [x](const tuple& t) { return get(t) == x; }); if (it != nums.end()) { get(*it)++; // 이미 vector에 존재하는 경우, 빈도..
2024.08.30 -
[BOJ] 1181번 : 단어 정렬
1. problem : https://www.acmicpc.net/problem/1181 2. solution 1 :#include using namespace std;int n;bool cmpw(const string& a, const string& b) { if (a.size() != b.size()) return a.size() > n; vector v; for (int i = 0; i > x; v.push_back(x); } sort(v.begin(), v.end(),cmpw); int cnt = 1; int idx = 1; while (cnt 3. solution 2 :// Authored by : tongnamuu// Co-authored by : -// http://boj.kr/e36..
2024.08.30 -
[BOJ] 5648번 : 역원소 정렬
1. problem : https://www.acmicpc.net/problem/5648 2. solution 1 :#include using namespace std;int n;vector v; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > x; v.push_back(x); } vector nums; for (string& s : v) { string temp; for (int i = s.size() - 1; i >= 0; i--) { if (!(temp.empty() && s[i] == 0)) temp.push_back(s[i]); } nums.push_back(stoll(te..
2024.08.30 -
[BOJ] 1914번 : 하노이 탑
1. problem : https://www.acmicpc.net/problem/1914 2. solution 1 :#include using namespace std;int n; string multiply(string a, string b) { int n = a.size(); int m = b.size(); vector result(n + m, 0); // a자리 * b자리 최대수는 a+b자리 for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { int mul = (a[i] - '0') * (b[j] - '0'); int sum = mul + result[i + j + 1]; result[i + j] += su..
2024.08.29 -
[BOJ] 11652번 : 카드
1. problem : https://www.acmicpc.net/problem/11652 2. solution 1 :#include using namespace std;int n;vector v; // number, cntint main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > x; v.push_back(x); } sort(v.begin(), v.end()); int idx = 0; int cnt = 0; long long maxVal = -(1ll 이 코드는 100% 정확한 코드가 아니다. 왜냐하면, 마지막 숫자에대해서는 고려하지 않았기때문이다. 물론, 마지막 숫자가 1개라면 영향이 없기때문에 , 정..
2024.08.29 -
[BOJ] 11651번 : 좌표 정렬하기 2
1. problem : https://www.acmicpc.net/problem/11651 2. solution 1 :#include using namespace std;int n;const int MXN = 100'002;vector> v(MXN+2);vector> temp(MXN + 2);void merge(int st, int en) { int mid = (st + en) / 2; int lidx = st; int ridx = mid; for (int i = st; i = en) return; int mid = (st + en) / 2; merge_sort(st, mid); merge_sort(mid, en); merge(st, en);}int main(void) { ios::sync_with..
2024.08.29