方法一:
#include <iostream> #include <queue> #include <vector> using namespace std; //究极愚蠢queue+vector模拟 tle int main() { queue<int>a; int N,M,judge,k,x; cin>>N; a.push(0); a.push(1); for(int i=2;i<=N;++i){ cin>>k>>judge; while(a.front()!=k){ a.push(a.front()); a.pop(); } if(judge==1){ a.push(a.front()); a.pop(); a.push(i); } else{ a.push(i); } } cin>>M; while(a.front()!=0){ a.push(a.front()); a.pop(); } a.pop(); vector<int>b; while(!a.empty()){ b.push_back(a.front()); a.pop(); } for(int i=0;i<M;++i){ cin>>x; for(int j=0;j<b.size();++j){ if(b[j]==x) b.erase(b.begin()+j); } } for(auto i:b){ cout<<i<<' '; } return 0; }
方法二:用链表形式,离散存储
#include <iostream>
using namespace std;
struct person{
int left,right,print;
}M[100010];
int n,m;
void add(int a,int b,int c){
if(b==1) //右
{
M[c].right=M[a].right;//插入点右变为原点右
M[c].left=a;//插入点左变为原点
M[a].right=c;//原点右变为插入点
M[M[c].right].left=c;//插入点右的左的左变为插入点
}
else //左
{
M[c].right=a;
M[c].left=M[a].left;
M[a].left=c;
M[M[c].left].right=c;
}
}
void erase(int x){
M[x].print=1;
}
int main() {
cin>>n;
int num1,num2,num;
add(0,1,1);
for(int i=2;i<=n;++i){
cin>>num1>>num2;
add(num1,num2,i);
}
cin>>m;
for(int i=0;i<m;++i){
cin>>num;
erase(num);
}
for (int i=M[0].right;i;i=M[i].right){
if (M[i].print==0) //输出未标记的
cout<<i<<" ";
}
return 0;
}
标签:right,队列,安排,cin,int,w4,front,push,left From: https://www.cnblogs.com/lijunjie03/p/17334959.html