https://www.acmicpc.net/problem/20006
20006번: 랭킹전 대기열
모든 생성된 방에 대해서 게임의 시작 유무와 방에 들어있는 플레이어들의 레벨과 아이디를 출력한다. 시작 유무와 플레이어의 정보들은 줄 바꿈으로 구분되며 레벨과 아이디는 한 줄에서 공백
www.acmicpc.net
생각해 보기
- 데이터를 어떤 식으로 저장하고 관리할지를 생각해야 한다.
- 같은 방 내부의 사람들은 이름의 사전순으로 출력해야 한다.
코드
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int p,m,l;
string n;
struct room{
int sl, el;
vector<pair<string, int> > party;
int cnt;
};
void input(){
cin>>p>>m;
}
void solution(){
vector<room> rooms;
while(p--){
cin>>l>>n;
bool enter=false;
for(int i=0,len=rooms.size();i<len;++i){
if(rooms[i].cnt<m&&rooms[i].sl<=l&&rooms[i].el>=l){
++rooms[i].cnt;
rooms[i].party.push_back({n,l});
enter=true;
break;
}
}
if(!enter){
vector<pair<string, int> > party;
party.push_back({n,l});
rooms.push_back({l-10,l+10,party,1});
}
}
for(int i=0,len=rooms.size();i<len;++i){
if(rooms[i].cnt == m){
cout<<"Started!"<<'\n';
}
else{
cout<<"Waiting!"<<'\n';
}
sort(rooms[i].party.begin(),rooms[i].party.end());
for(auto it: rooms[i].party){
cout<<it.second<<" "<<it.first<<'\n';
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
solution();
return 0;
}

728x90
'알고리즘 > 백준 문제' 카테고리의 다른 글
| 2304 - 창고 다각형 (0) | 2023.03.10 |
|---|---|
| 11501 - 주식 (0) | 2023.03.10 |
| 22233 - 가희와 키워드 (0) | 2023.03.08 |
| 19637 - IF 좀 대신 써줘 (0) | 2023.03.07 |
| 20310 - 타노스 (0) | 2023.03.07 |
댓글