본문 바로가기

백준 문제 풀이 & C++ 공부54

백준 2109 C++ https://www.acmicpc.net/problem/2109이건 별로 어려움 없이 풀었다. #include using namespace std;typedef long long ll;int n; //강연 요청을 한 대학 횟수int maxDay = 0;ll result;//int d; //d일안에 강의해라//int p; //강연료vector> lecs; //day, pay순vector days;priority_queue> pq;priority_queue paypq;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int d, p; for (int i = 0; i > p >> d; if (d > maxDay).. 2024. 6. 23.
백준 1202 C++ https://www.acmicpc.net/problem/1202이 문제 고민했던 점이 무게가 작은 보석부터 가방에 넣어야한다는 점을 인지하고 sort까진 했다.근데 문제는 가격이었다. 무게가 같은 것이라도 분명히 가격이 다른 것이 존재할 경우가 있다고 생각했다. 처음 생각한 것은 sort한 vector의 index를 올리면서 해당 보석을 넣고 안넣고 안들어가면 가방의 index를 높이는 방식이었다.이건 n, k가 300,000이기 때문에 안될 것이라고 생각했다. 그 이후 가장 작은 가방에 들어갈 수 있는 보석은 다음 가방에도 들어갈 수 있다는 것이 떠올랐다.그렇다면 priority_queue를 만들고 가격을 기준으로 정렬하면 된다. #include using namespace std;typedef lo.. 2024. 6. 21.
백준 1062 C++ https://www.acmicpc.net/problem/1062 이 문제에서 제일 고민했던 부분은 배운 알파벳 선택을 어떻게 할까였다.배우는 알파벳 개수는 정해져있기 때문에 재귀적으로 개수가 맞으면 그때 배운 알파벳에 따라서 몇개의 단어를 배울 수 있는지 count했다. #include using namespace std;//antic -> acint -> 1 3 9 14 20 -> 0 2 8 13 19int n, k; //n은 단어, k는 charint result = 0;int learn = (1 v;void learnAlpha(int a, int startIndex, int count) { if (count == k) { int c = 0; for (auto i : v) { if ((i.. 2024. 6. 6.
백준 5430 C++ https://www.acmicpc.net/problem/5430이 문제 쉬웠는데 억울한 문제였다.코드 제일 마지막 부분에 cout 이거 때문에 헤맸다.출력과 관련해서 한 줄을 띄워야한다던데 명확한 기준이 있었으면 좋았을거 같다.#include #include #include #include using namespace std;int testCase;deque d;string ACS, arrString;int arrCount;int main(){ ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); cin >> testCase; for (int t = 0; t > ACS; cin >> arrCount; cin >> arrString; int num=0; .. 2024. 5. 30.