题解:CF749C Voting

· · 题解

一道小清新思维题。

考虑使用两个队列分别维护 R 团队和 D 团队的成员的发言时间。

对于每次操作:

代码主体部分如下:

int v[200006];
queue <int> q[5];
map <char, int> m;
int main() {
    m['D'] = 1, m['R'] = 2;
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) q[m[s[i]]].push(i + 1);
    while (1) {
        if (q[1].empty()) {
            cout << 'R';
            return 0;
        }
        if (q[2].empty()) {
            cout << 'D';
            return 0;
        }
        int t1 = q[1].front(), t2 = q[2].front();
        if (t1 < t2) {
            q[2].pop();
            q[1].pop();
            q[1].push(t1 + n);
        }
        else {
            q[1].pop();
            q[2].pop();
            q[2].push(t2 + n);
        }
    }
}