文章

119

粉丝

68

获赞

92

访问

20.1k

头像
集合交并 题解:map,set一起用
P1813 复旦大学2018年机试
发布于2025年2月14日 10:42
阅读数 31

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;
	while(cin>>n>>m){
	    map<int,int>mp;
	    while(n--){
	        int x;cin>>x;
	        if(mp[x]==0)mp[x]++;
	    }
	    set<int>l;
	    while(m--){
	        int x;cin>>x;
	        l.insert(x);
	    }
	    for(auto x:l){
	        mp[x]++;
	    }
	    int a=0,b=0;
	    for(auto x:mp){
	        if(x.second>1)a++;
	        b++;
	    }
	    cout<<a<<' '<<b<<endl;
	}

}

map用于检索集合并交状态,set用于去重

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发