분류 전체보기

    [골5] 9663 - N-Queen

    #include using namespace std; int n, answer = 0; int vis[15]{ 0 }; // 유망한지 체크 bool Check(int cnt) { for (int i = 0; i < cnt; i++) { auto vis1 = vis[cnt], vis2 = vis[i]; if (vis1 == vis2 || cnt - i == abs(vis1 - vis2)) return 0; } return 1; } void BackTracking(int cnt) { if (cnt == n) { answer++; return; } for (int i = 0; i < n; i++) { vis[cnt] = i; if (Check(cnt)) BackTracking(cnt + 1); } } int ..

    C++ 간단하게 사용할 수 있는 포인터 해제 매크로 함수

    #include using namespace std; #define SAFETY_CHECK(ptr) \ { \ if (ptr == nullptr) \ { \ cout

    [골5] 14503 - 로봇 청소기

    수정된 코드 #include #define MAX 51 #define y first #define x second using namespace std; struct Robot { int y, x, d; Robot() = default; Robot(int y, int x, int d = 0) : y(y), x(x), d(d) { } } robot; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int h, w; cin >> h >> w; cin >> robot.y >> robot.x >> robot.d; auto& y = robot.y, & x = robot.x, & d = robot.d; if (d == 1) d..

    [실3] 1966 - 프린터 큐

    #include #include #include #include using namespace std; #define y front().first #define x front().second int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int tc; cin >> tc; for (int i = 0; i > t >> f; queue q; priority_queue pq; for (int j = 0; j > val; q.push({ j,val }); pq.push(val); } ..

    [실3] 1021 - 회전하는 큐

    #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int s, n, cnt = 0; cin >> s >> n; deque dq; for (int i = 1; i > num; for (int i = 0; i < s; i++) { if (dq[i] == num) { idx = i; break; } } for (int i = 0; i < dq.size(); i++) { if (dq.front() == num) { dq.pop_front(); break; } if (idx < dq.size() / 2 + 1) { dq.push_back(dq..

    [골5] 2023 - 신기한 소수

    #include #include #include #include using namespace std; int n = 0; bool Prime(int num) { for (int i = 2; i * i

    [골2] 10800 - 컬러볼

    #include #include #include #include using namespace std; struct sColorBall { int n, color, size; sColorBall() = default; sColorBall(int n, int color, int size):n(n),color(color),size(size) { } }; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector vecBall(n); for (int i = 0; i > vecBall[i].color >> vecBall[i].size; } sort(vecB..

    구조체 또는 클래스 관련 정렬 (sort 함수)

    구조체 또는 클래스는 항상 연산자 오버로딩을 해줘야하고 클래스명으로 가야한다. struct Student { int id, pow; char team; Student(int a, char b, int c) : id(a),team(b),pow(c) { } bool operator(const Student& b) const { return pow > b.pow; } }; 여기서 pow 기준으로 정렬할텐데 이때 algorithm 헤더파일 내에 sort 함수를 사용하고 pred 인자로 해당 연산자 오버로딩 함수를 보내주면 된다. 디폴트 값 : less(); vector st; // pred 템플릿 인자로 무조건 클래스명으로 줘야한다. sort(st.begin(), st.end(), greater()); less..

    CPU의 역사

    최초의 16비트 CPU: 인텔 8086 / 8088(1978년) 1971년에 출시된 인텔의 '4004'가 원조다. 하지만 이는 전자계산기와 같은 특정 목적 단말기용으로 주로 쓰였으며, 오늘날 우리가 쓰는 PC(퍼스널컴퓨터)용 CPU의 원조는 1978년에 나온 인텔의 16비트 CPU인 8086, 그리고 그 자매품인 8088이라 할 수 있다. 이 때문에 지금도 PC용 CPU는 ‘x86 계열’이라 부른다. 최초의 32비트 CPU: 인텔 80386(1986년) 1980년대에 들어 PC의 이용 범위가 급격히 넓어지면서 한층 고성능의 CPU가 요구되었다. 1986년에 출시된 인텔 80386은 32비트 명령어를 처리할 수 있는 최초의 x86계열 CPU로, 흔히 ‘386’이라는 이름으로 불리곤 했다. 80386이 큰 ..

    멀티 스레드 렌더링 (Multi Thread Rendering)

    왜 해야할까? Direct3D 11 이전의 그래픽스 API는 단일 스레드에서 실행되는 것을 중점으로 두고 설계되었다. 암시적인 동기화 지점이 존재해서 API를 호출하고 난 다음 GPU의 처리가 완료 되었을 때 이후의 코드가 실행된다, 문제는 이렇게 순서를 맞춰서 진행하는 방식은 CPU와 GPU를 최대로 활용하지 못하는 점이다. CPU 계산 중에 GPU는 제출된 명령이 없기 때문에 아무런 일도 하지않고 CPU의 처리를 기다리게 되고 렌더링 중에는 동기화 지점으로 인해서 CPU는 GPU의 처리가 끝날 때 까지 기다리게 된다. 따라서 CPU와 GPU가 비효율적으로 사용되지 않도록 스레드를 분리하여 렌더링과 CPU 계산이 동시에 이뤄지도록 해야한다. GPU가 무언가를 그리도록 요청하기 위해서 그래픽스 API를 ..