pat-1121

This kind of question first looks for the rules, what will happen to the other after one of them appears 

#include<iostream>
#include<vector>
#include<set>
using namespace std;
int main(){
	int n,temp1,temp2,m;
	scanf("%d",&n);
	vector<int>cou(100000);
	for(int i=0;i<100000;i++){
		cou[i]=-1;
	}
    for(int i=0;i<n;i++){
    	scanf("%d %d",&temp1,&temp2);
		cou[temp1]=temp2;
		cou[temp2]=temp1;
	}
	vector<int> exist(100000);
	vector<int>a;
    scanf("%d",&m);
    set<int> ans;
    for(int i=0;i<m;i++){
    	scanf("%d",&temp1);
    	a.push_back(temp1);
    	if(cou[temp1]!=-1){
    		exist[cou[temp1]]=1;
		}
	}
	for(int i=0;i<a.size();i++){
		if(exist[a[i]]!=1 ) ans.insert(a[i]); 
	}
	printf("%d\n",ans.size());
	for(auto it=ans.begin();it!=ans.end();it++){
		if(it!=ans.begin())printf(" ");
		printf("%05d",*it);
	}
return 0;
}

to sum up

1. Use hashing as much as possible, try to use as little as possible. Nesting with for loops is easy to time out, and more memory is not a big problem

2. 5 digit, %05d, don’t fall in front

3. If you just say from small to large, and there are no repeated elements, just use set directly, or do not require repeated elements, or even overload

English 

The question summarizes the ideas, the data given, and the type of data you are looking for. What should I use at this time?

 

 

 

 

Guess you like

Origin blog.csdn.net/m0_45359314/article/details/113090523