알고리즘
백준 20006번 랭킹전 대기열 C++
영춘권의달인
2023. 4. 25. 17:46
https://www.acmicpc.net/problem/20006
20006번: 랭킹전 대기열
모든 생성된 방에 대해서 게임의 시작 유무와 방에 들어있는 플레이어들의 레벨과 아이디를 출력한다. 시작 유무와 플레이어의 정보들은 줄 바꿈으로 구분되며 레벨과 아이디는 한 줄에서 공백
www.acmicpc.net
#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;
struct PlayerInfo {
int level;
string name;
bool operator<(const PlayerInfo& other) const {
return name < other.name;
}
bool operator>(const PlayerInfo& other) const {
return name > other.name;
}
};
int p, m;
vector<vector<PlayerInfo>> room;
vector<pair<int, int>> roomRange;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> p >> m;
for (int i = 0; i < p; i++) {
int level;
string name;
cin >> level >> name;
bool _push = false;
for (int i = 0; i < room.size(); i++) {
int left = roomRange[i].first;
int right = roomRange[i].second;
if (level<left || level>right) continue;
if (room[i].size() == m) continue;
room[i].push_back({ level,name });
_push = true;
break;
}
if (_push) continue;
vector<PlayerInfo> v;
room.push_back(v);
roomRange.push_back({ level - 10,level + 10 });
room[room.size() - 1].push_back({ level,name });
}
for (auto &a : room) {
sort(a.begin(), a.end());
}
for (auto a : room) {
if (a.size() == m) cout << "Started!\n";
else cout << "Waiting!\n";
for (auto b : a) {
cout << b.level << " " << b.name << "\n";
}
}
}