1063. Set Similarity

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1063

使用set,简单数学题。

// set::find()找不到时返回的是set::end()
//


#pragma warning(disable: 4786)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define SIZE 10000+10

using namespace std;

set<int> All_set[100];

int n, m, k;

void input()
{
	int i;
	for(i=1; i<=n; i++)
	{
		scanf("%d", &m);
		while(m-- > 0)
		{
			int t;
			scanf("%d", &t);
			All_set[i].insert(t);
		}
	}
}

void processing()
{
	scanf("%d", &k);
	while(k-- > 0)
	{
		int set1, set2;
		scanf("%d%d", &set1, &set2);
		int same=0;
		set<int>::iterator it = All_set[set1].begin();
		for( ; it != All_set[set1].end(); it++)
		{
			if(All_set[set2].find((*it)) != All_set[set2].end())
			{
				same++;
			}
		}
		int total = All_set[set1].size() + All_set[set2].size() - same;
		printf("%.1lf%%\n", 100.0*same / total);
	}
}


int main()
{
	#ifdef ONLINE_JUDGE
	#else
		freopen("E:\\in.txt", "r", stdin);
	#endif

	// input
	scanf("%d", &n);
	input();
	processing();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值