来自http://blog.csdn.net/tiantangrenjian/article/details/16868399

set_intersection 交集  set_union 并集  set集合没有重复数字

#include <iostream>
#include <vector>
#include <set>
#include <algorithm> // set_intersection
#include <iterator> //inserter 
#include <stdio.h>
using namespace std;
int n,m[50],k;
vector<int> numSet[50];
set<int> nset[50];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m[i];
		for(int j=0;j<m[i];j++){
			int tmp;
			cin>>tmp;
			nset[i].insert(tmp);
		}
	}
	cin>>k;
	set<int> res;
	int nc,nt;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		set_intersection(nset[a-1].begin(),nset[a-1].end(),nset[b-1].begin(),nset[b-1].end(),inserter(res,res.begin()));
		nc=res.size();
		nt=nset[a-1].size()+nset[b-1].size()-nc;
		res.clear();
		printf("%2.1f%%\n",nc*100.0/nt);
	}
	return 0;
}

  

相关文章:

  • 2022-12-23
  • 2021-08-22
  • 2021-04-26
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-09-04
  • 2021-07-16
猜你喜欢
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2021-04-20
相关资源
相似解决方案