1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
P1160 队列安排.cpp 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 2024-01-09 00:01 . move from github to gitee
#include <iostream>
using namespace std;
struct mem{
int left,right;
bool vis=false;
};
int main(){
int start=0;
int n;
cin>>n;
mem a[n];
a[0].left = -1;
a[0].right = -1;
a[0].vis = true;
for(int i=1;i<n;i++){
int k,p;
cin>>k>>p;
k--;
if(p == 0){
a[i].right = k;
a[i].left = a[k].left;
a[k].left = i;
if(a[i].left == -1)
start = i;
else{
a[a[i].left].right = i;
}
}
else{
a[i].left = k;
a[i].right = a[k].right;
a[k].right = i;
if(a[i].right != -1){
a[a[i].right].left = i;
}
}
a[i].vis = true;
}
// cout<<endl<<endl;
// int index=start;
// while(a[index].right != -1){
// cout<<index+1<<" ";
// index = a[index].right;
// }
// cout<<index+1;
// cout<<endl<<endl;
int m;
cin>>m;
for(int i=0;i<m;i++){
int x;
cin>>x;
x--;
if(a[x].vis == false)
continue;
if(a[x].left != -1)
a[a[x].left].right = a[x].right;
if(a[x].right != -1)
a[a[x].right].left = a[x].left;
a[x].vis = false;
if(a[a[x].right].left == -1)
start = a[x].right;
}
while(a[start].right != -1){
cout<<start+1<<" ";
start = a[start].right;
}
cout<<start+1<<endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385