STL求优化
查看原帖
STL求优化
747883
xhz0311楼主2023/2/25 20:48
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,m,k,p,x;
	list<int> a;
	list<int>::iterator it;
	a.push_front(1);
	cin>>n;
	for (int i=2; i<=n; i++)
	{
		scanf("%d %d",&k,&p);
		for (it=a.begin(); it!=a.end(); it++)
		{
			if (*it==k)
			{
				break;
			}
		}
		if (p==1)
		{
			it++;
		}
		a.insert(it,i);
	}
	cin>>m;
	int ind[m];
	for (int i=1; i<=m; i++)
	{
		scanf("%d",&x);
		ind[i]=x; bool flag=false;
		for (int j=1; j<i; j++)
		{
			if (ind[j]==x)
			{
				flag=true;
			}
		}
		if (!flag)
		{
			for (it=a.begin(); it!=a.end(); it++)
			{
				if (*it==x)
				{
					break;
				}
			}
			list<int>::iterator now=it;
			a.erase(now);
		}
	}
	for (it=a.begin(); it!=a.end(); it++)
	{
		printf("%d ",*it);
	}
	return 0;
}
2023/2/25 20:48
加载中...