본문 바로가기

전체 글

(233)
[C++] 백준 2563번 - 색종이 문제 2563번https://www.acmicpc.net/problem/2563  #include using namespace std;int paper[100][100];int main() { int n, x, y, cnt = 0; cin >> n; for (int i = 0; i > x >> y; for (int j = 0; j
[C++] 백준 15652번 - N과 M (4) 문제 15652번https://www.acmicpc.net/problem/15652 dfs에 매개변수로 보내주는 것 중 첫번째 값을 i로 보내주면 된다. #include using namespace std;int n, m;int num[9];bool visited[9];void dfs(int index, int cnt) { if (cnt == m) { for (int i = 0; i > n >> m; dfs(1, 0); return 0;}
[C++] 백준 15651번 - N과 M (3) 문제 15651번https://www.acmicpc.net/problem/15651 뽑은 것을 다시 뽑을 수 있도록 N과 M (1)에서 작성했던 코드에서 if(!visited[i]) 부분을 제거해준다.#include using namespace std;int n, m;int num[9];bool visited[9];void dfs(int a) { if (a == m) { for (int i = 0; i > n >> m; dfs(0); return 0;}
[C++] 백준 15650번 - N과 M (2) 문제 15650번https://www.acmicpc.net/problem/15650 중복되는 값은 제외하기 위해 dfs 함수를 다시 실행할 때 인덱스값을 넘겨주었다. #include using namespace std;int n, m;int num[9];bool visited[9];void dfs(int a, int b) { if (b == m) { for (int i = 0; i > n >> m; dfs(1, 0); return 0;}
[C++] 백준 15649번 - N과 M(1) 문제 15649번https://www.acmicpc.net/problem/15649  #include using namespace std;int n, m;int num[9];bool visited[9];void dfs(int a) { if (a == m) { for (int i = 0; i > n >> m; dfs(0); return 0;}
[C++] 백준 1269번 - 대칭 차집합 문제 1269번https://www.acmicpc.net/problem/1269  입력받은 값이 map에 있다면 그 원소를 지워주고, 아니면 있다고 true를 넣어준다.그렇게 map의 size()를 통해 남은 원소의 개수를 출력하여 답을 구한다.  #include #include using namespace std;int main() { map num; int a, b, temp; cin >> a >> b; for (int i = 0; i > temp; if (num[temp] == true) { num.erase(temp); } else { num[temp] = true; } } cout
[C++] 백준 11286번 - 절댓값 힙 문제 11286번https://www.acmicpc.net/problem/11286 구조체와 operator 함수를 이용해서 정렬하는 방법을 정의해준다.절댓값이 같다면 가장 작은 원소를 리턴해주고, 아니면 절댓값이 작은 원소를 리턴해준다. #include #include #include using namespace std;struct compare { bool operator()(int a, int b) { if (abs(a) == abs(b)) { return a > b; } return abs(a) > abs(b); }};int main() { int n, x; vector v; priority_queue, compare> pq; cin >> n; for (int ..
[C++] 백준 1927번 - 최소 힙 문제 1927번https://www.acmicpc.net/problem/1927 어제와는 반대로 내림차순으로 정렬해주는 우선순위 큐를 선언한다(priority_queue부분). #include #include #include using namespace std;int main() { int n, x; vector v; priority_queue, greater> pq; cin >> n; for (int i = 0; i > x; if (x == 0) { if (pq.empty()) { v.push_back(0); } else { v.push_back(pq.top()); pq.pop(); } } else { pq.push(x); } } for (int i = 0; i