# 题解 CF546C()-其他

## 题解 CF546C()

### 题解 CF546C

codeforces网址

``STl``
``queue``

``front``
``front``

``push``
``push``

``10^4``

``````#include<cstdio>
#include<queue>
using namespace std;
queue<int> q[3];
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=2;i++){
scanf("%d",&n);
for(int j=1;j<=n;j++){
int x;
scanf("%d",&x);
q[i].push(x);
}
}
for(int i=1;i<10000;i++){
if(q[1].empty()){
printf("%d 2",i-1);
return 0;
}
if(q[2].empty()){
printf("%d 1",i-1);
return 0;
}
if(q[1].front()>q[2].front()){
int t=q[1].front();
q[1].pop();
q[1].push(q[2].front());
q[2].pop();
q[1].push(t);
}else{
int t=q[2].front();
q[2].pop();
q[2].push(q[1].front());
q[1].pop();
q[2].push(t);
}
}
printf("-1");
return 0;
}
``````
————————

### 题解 CF546C

codeforces网址

``STl``
``queue``

``front``
``front``

``push``
``push``

``10^4``

``````#include<cstdio>
#include<queue>
using namespace std;
queue<int> q[3];
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=2;i++){
scanf("%d",&n);
for(int j=1;j<=n;j++){
int x;
scanf("%d",&x);
q[i].push(x);
}
}
for(int i=1;i<10000;i++){
if(q[1].empty()){
printf("%d 2",i-1);
return 0;
}
if(q[2].empty()){
printf("%d 1",i-1);
return 0;
}
if(q[1].front()>q[2].front()){
int t=q[1].front();
q[1].pop();
q[1].push(q[2].front());
q[2].pop();
q[1].push(t);
}else{
int t=q[2].front();
q[2].pop();
q[2].push(q[1].front());
q[1].pop();
q[2].push(t);
}
}
printf("-1");
return 0;
}
``````