본문 바로가기

Problem Solving

(152)
[백준/C++/KOI] 25378번 조약돌 풀이 모든 조약돌을 가져가는 최대 횟수는 2번 작업을 N번 반복하는 것이다. 그렇다면 1번 작업을 통해서 횟수를 줄여나갈 수 있는데 1번 작업으로 횟수를 줄이려면 인접한 장소의 조약돌을 모두 가져가는 경우일 것이다. (ex: [1, 1] [1 2 1]) 예시 5 2, 3, 6, 10, 5 왼쪽에서부터 차례로 모든 조약돌을 오른쪽에 있는 조약돌에서 같은 개수를 가져간다. 첫번째 돌부터 1번작업을 시작하는 경우 두번째 돌부터 1번작업을 시작하는 경우 ... 으로 경우를 나눌 수 있고 그렇게 0이 되는 순간 작업 횟수가 1번 줄어드는 것을 확인할 수 있다. 음수만큼 가져갈 수 없으니 이 경우 끊어준다. // This Code is written by gloryko fpqpsxh. 2 4 5 5 #include #i..
[백준/C++] 1005번 ACM Craft 이 문제를 처음 봤을 때는 최단경로 (Shortest Path)문제라고 생각하였습니다. 그래서 맨 뒤에서부터 각 Tree Level마다 걸리는 최대 시간을 찾아 return하면 되겠다고 생각하였습니다. 주어지는 간선(edge)를 거꾸로 받아서 출발하는 간선이 없는 노드(vertax)를 도착점으로 하면 되겠다고 생각하였으나, 교차되거나 복잡하게 꼬여있는 곳에서 오류가 생긴다는 것을 알게 되었고 왜 사용하지 못하는가에 자세한 사항은 아래 링크를 넣겠습니다. 아래 링크에 bfs, dfs,다익스트라, 재귀 등등 중요한 꿀팁이 들어있습니다. https://www.acmicpc.net/board/view/30959 글 읽기 - ★☆★☆★ [필독] ACM Craft FAQ ★☆★☆★ 댓글을 작성하려면 로그인해야 합니..
[백준/C++] 24268번 2022는 무엇이 특별할까? #include using namespace std ; int main() { int year, bits, value; cin >> year >> bits ; vector arr(bits); iota(arr.begin(), arr.end(), 0) ; while(next_permutation(arr.begin(), arr.end())) { if(arr[0] == 0) continue; value = 0; for(int i = 0 ; i year) { cout
[백준/C++] 2941번 크로아티아 알파벳 #include using namespace std; int main() { string temp; cin >> temp; string croatiaLangue[] = { "c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z=" }; for(string it : croatiaLangue) { string::size_type sub = temp.find(it); while(sub != temp.npos) { temp.replace(sub,it.length(),"#"); sub = temp.find(it); } } cout
[백준/C++] 1755번 숫자놀이 #include #include #include #include #include #include #include #include using namespace std; string arr[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; bool compare(const string& a, const string& b) { for(int i = 0; i > N..
[백준/C++] 1431번 시리얼 번호 #include #include #include #include #include #include #include #include using namespace std; bool compare(const string &a, const string &b) { if(a.length() != b.length()) return a.length() < b.length(); else { int sum_A = 0; int sum_B = 0; for(int i = 0; i < a.length(); i++) { if(isdigit(a[i])) sum_A += (a[i] - '0'); if(isdigit(b[i])) sum_B += (b[i] - '0'); } return sum_A == sum_B ? a < b : sum_..
[백준/C++] 11656번 접미사 배열 #include #include #include #include #include #include #include using namespace std; int main() { string temp; cin >> temp; vector arr; while(!temp.empty()) { arr.push_back(temp); temp = temp.substr(1,temp.length()); } sort(arr.begin(), arr.end()); for(auto it : arr) { cout
[백준/C++] 10867번 중복 빼고 정렬하기 #include #include #include #include #include #include #include using namespace std; int main() { int N; cin >> N; vector arr(N); for(int i = 0; i > arr[i]; } sort(arr.begin(), arr.end()); arr.erase(unique(arr.begin(),arr.end()), arr.end()); for(int it : arr) { cout