Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dota2 Senate #96

Closed
Tracked by #101
fkdl0048 opened this issue Oct 15, 2024 · 1 comment
Closed
Tracked by #101

Dota2 Senate #96

fkdl0048 opened this issue Oct 15, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Oct 15, 2024

#include <queue>
#include <string>

using namespace std;

class Solution {
public:
    string predictPartyVictory(string senate) {
        queue<int> queueR, queueD;
        int n = senate.size();

        // Radiant와 Dire 상원의원의 인덱스를 각각의 큐에 저장
        for (int i = 0; i < n; i++) {
            if (senate[i] == 'R') {
                queueR.push(i);
            } else {
                queueD.push(i);
            }
        }

        // 두 큐가 비어있지 않으면 계속 투표
        while (!queueR.empty() && !queueD.empty()) {
            int r_index = queueR.front();
            int d_index = queueD.front();
            queueR.pop();
            queueD.pop();

            // 더 작은 인덱스의 상원의원이 상대방을 추방하고, 다음 투표를 준비
            if (r_index < d_index) {
                // Radiant 상원의원이 이겼으므로, 다시 투표 가능
                queueR.push(r_index + n);
            } else {
                // Dire 상원의원이 이겼으므로, 다시 투표 가능
                queueD.push(d_index + n);
            }
        }

        // Radiant 상원의원이 남아 있으면 Radiant 승리, 아니면 Dire 승리
        return queueR.empty() ? "Dire" : "Radiant";
    }
};
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Oct 15, 2024
@fkdl0048 fkdl0048 added this to Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Oct 15, 2024
@fkdl0048 fkdl0048 moved this from Todo to In Progress in Todo Oct 15, 2024
@fkdl0048 fkdl0048 added this to the LeetCode milestone Oct 15, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048
Copy link
Owner Author

  • 문제 자체가 복잡하고 이해하기 힘든 문제였으나 답지를 보고 이해함..
  • DFS개념과 같이 큐를 사용한 반복이 핵심

@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
75 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant