40pts 求助
查看原帖
40pts 求助
964306
orpg楼主2024/11/22 10:43
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e2+5;
int n,m,k;
int cow[maxn],cow1[maxn],o[maxn],vis[maxn],order[maxn];
main(){
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		int x;
		cin>>x;
		order[x]=i;// cow x is at number i
		o[i]=x;// number i is cow x;
		
	}
	for(int i=1;i<=k;i++){
		int x,y;
		cin>>x>>y;
		cow[y]=x;// place y is cow x
		cow1[x]=y;// cow x is at place y
		if(order[x]!=0){
			vis[y]=1;
		}
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==1){
			int cnt=order[cow[i]]-1;
			for(int j=i-1;j>=1;j--){
				if(cow[j]!=0) continue;
				else if(cow1[o[cnt]]!=0) break;
				else if(cow[j]==0){
					cow[j]=o[cnt];
					cow1[o[cnt]]=j;
					cnt--;
				}
				else if(order[cow[j]]==cnt){
					cnt--;
				}
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
//		cout<<i<<" is cow :"<<cow[i]<<'\n'; 
		if(cow[i]==0){
			ans=i;
			break;
		}
	}
	cout<<ans;
	return 0;
} 
2024/11/22 10:43
加载中...