题解 | #[USACO 2009 Ope S]Cow Line#
[USACO 2009 Ope S]Cow Line
https://ac.nowcoder.com/acm/problem/24876
这是到典型的双端队列题,运用模拟思想将牛队列看作是双端队列即可。
int times;
cin>>times;
deque<int> cows;
int ncow=1;
char order;
char side;
while(times--){
cin>>order>>side;
if(order=='A'){
if(side=='L'){
cows.push_front(ncow++);
}else{
cows.push_back(ncow++);
}
}else if(order=='D'){
int nums;
cin>>nums;
if(side=='L'){
while(nums--){
cows.pop_front();
}
}else{
while(nums--){
cows.pop_back();
}
}
}
}
while(!cows.empty()){
cout<<cows.front()<<endl;
cows.pop_front();
}