260312 TIL - 챕터4 멀티플레이어 게임 개발 4일차

2026. 3. 12. 21:04언리얼 7기 본캠프

//네트워크 문제. DFS를 써도 되는데, BFS가 아직 미숙하니 BFS를 이용해서 풀어봤음.
//DFS든 BFS든 연결된 네트워크 전체를 탐색만 하면 되니까... 겸사겸사 BFS를 함수로 빼는것도 시험해봄
#include <string>
#include <vector>
#include <queue>

using namespace std;

void BFS(const int& n, const vector<vector<int>>& computers, queue<int>& q, vector<bool>& isvisited)
{
    while(!q.empty())
    {
        int current = q.front();
        q.pop();
        for(int i = 0; i < n; i++)
        {
            if (computers[current][i] == 1 && !isvisited[i])
            {
                q.push(i);
                isvisited[i] = true;
            }
        }
    }
}

int solution(int n, vector<vector<int>> computers) {
    int answer = 0;
    queue<int> q;
    vector<bool> isvisited(n);
    
    for(int i = 0; i < n; i++)
    {
        if (!isvisited[i])
        {
            answer++;
            q.push(i);
            isvisited[i] = true;
            BFS(n, computers, q, isvisited);
        }
    }
    return answer;
}
//구명보트 문제. 그리디 + 투 포인터 문제였는데, 여전히 투 포인터가 좀 익숙하지 않은듯함
//내일은 투 포인터 관련 문제를 조금 더 풀어보는것도 좋을듯
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> people, int limit) {
    int answer = 0;
    int left = 0, right = people.size() - 1;
    sort(people.begin(), people.end());
    while(left <= right)
    {
        if (people[left] + people[right] <= limit)
        {
            left++;
            right--;
            answer++;
        }
        else
        {
            right--;
            answer++;
        }
    }
    return answer;
}

 

오늘은 강의를 6강까지 겨우 완강했고, 복습하면서 실습내용을 다시 만들어보고 있는데, RPC와 Replication등이 여전히 좀 헷갈리는 부분이 있어서 꼼꼼히 학습하고 넘어가야 할 것 같음. 멀티플레이의 핵심 내용이다보니 이게 반드시 작동해야 이후에 뭘 하든 넘어갈 수 있을 것 같음...