Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자료구조
- 트리
- XR Interaction Toolkit
- 스택
- 다익스트라
- 유니티
- 구현
- 우선순위 큐
- 알고리즘
- 수학
- 백트래킹
- DFS
- 그래프
- Team Fortress 2
- Unreal Engine 5
- 누적 합
- 정렬
- 재귀
- 시뮬레이션
- 문자열
- ue5
- BFS
- 백준
- 브루트포스
- VR
- 다이나믹 프로그래밍
- 투 포인터
- 유니온 파인드
- 그리디 알고리즘
- c++
Archives
- Today
- Total
1일1알
Judge - 1233 : 한기대 최고의 보안 시스템 C++ 본문
아무것도 없는 상태에서 시작해서 1이 있는 비트의 수가 짝수개라면 뒤에 0을 추가하고, 1이 있는 비트의 수가 홀수개라면 뒤에 1을 추가하는 식으로 해서 백트래킹을 이용해서 풀었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int k;
void BT(int num, int cntOf1, int size) {
if (size >= k) {
cout << num << " ";
return;
}
if (cntOf1 % 2 == 0) {
BT(num << 1, cntOf1, size + 1);
BT((num << 1) | 1, cntOf1 + 1, size + 1);
}
else {
BT((num << 1) | 1, cntOf1 + 1, size + 1);
BT(num << 1, cntOf1, size + 1);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
cin >> k;
BT(0, 0, 1);
BT(1, 1, 1);
cout << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 1644번 소수의 연속합 C++ (0) | 2022.07.19 |
---|---|
Judge - 1231 : 양궁 선수 순위 예측 C++ (0) | 2022.07.18 |
Judge - 1236 : 넌 얼마나 빠르게 왔었니? (0) | 2022.07.16 |
Judge - 1235 : Please In My Frontyard! C++ (0) | 2022.07.15 |
Judge - 1170 : 크리스마스의 요정 C++ (0) | 2022.07.14 |