1063 Set Similarity (25 分)
 

Given two sets of integers, the similarity of the sets is defined to be /, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

Input Specification:

Each input file contains one test case. Each case first gives a positive integer N (≤) which is the total number of sets. Then N lines follow, each gives a set with a positive M (≤) and followed by M integers in the range [0]. After the input of sets, a positive integer K (≤) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

Output Specification:

For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

Sample Input:

3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
2
1 2
1 3

Sample Output:

50.0%
33.3%

题意:

  比较两个set<int>集合的相似度。

code:

 #include<bits/stdc++.h>
using namespace std;
vector<set<int> > sets;
int main(){
int n,m,k,a1,a2;
scanf("%d",&n);
sets.resize(n);
for (int i = ; i < n; i++)
{
scanf("%d",&m);
set<int> temp;
for (int j=;j<m;j++)
{
int num;
scanf("%d",&num);
temp.insert(num);
}
sets[i]=temp;
}
scanf("%d",&k);
for (int i=;i<k;i++)
{
scanf("%d %d",&a1,&a2);
int nc=,nt = sets[a2-].size();
for (auto it=sets[a1-].begin();it!=sets[a1-].end();it++)
{
if (sets[a2-].find(*it)==sets[a2-].end())
nt++;
else
nc++;
}
printf("%.1lf%%\n",(double)nc/nt*);
}
return ;
}

【算法笔记】A1063 Set Similarity的更多相关文章

  1. 学习Java 以及对几大基本排序算法(对算法笔记书的研究)的一些学习总结(Java对算法的实现持续更新中)

    Java排序一,冒泡排序! 刚刚开始学习Java,但是比较有兴趣研究算法.最近看了一本算法笔记,刚开始只是打算随便看看,但是发现这本书非常不错,尤其是对排序算法,以及哈希函数的一些解释,让我非常的感兴 ...

  2. 算法笔记--数位dp

    算法笔记 这个博客写的不错:http://blog.csdn.net/wust_zzwh/article/details/52100392 数位dp的精髓是不同情况下sta变量的设置. 模板: ]; ...

  3. 算法笔记--lca倍增算法

    算法笔记 模板: vector<int>g[N]; vector<int>edge[N]; ][N]; int deep[N]; int h[N]; void dfs(int ...

  4. 算法笔记--STL中的各种遍历及查找(待增)

    算法笔记 map: map<string,int> m; map<string,int>::iterator it;//auto it it = m.begin(); whil ...

  5. 算法笔记--priority_queue

    算法笔记 priority_queue<int>que;//默认大顶堆 或者写作:priority_queue<int,vector<int>,less<int&g ...

  6. 算法笔记--sg函数详解及其模板

    算法笔记 参考资料:https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html sg函数大神详解:http://blog.csdn.net/l ...

  7. 算法笔记——C/C++语言基础篇(已完结)

    开始系统学习算法,希望自己能够坚持下去,期间会把常用到的算法写进此博客,便于以后复习,同时希望能够给初学者提供一定的帮助,手敲难免存在错误,欢迎评论指正,共同学习.博客也可能会引用别人写的代码,如有引 ...

  8. 算法笔记_067:蓝桥杯练习 算法训练 安慰奶牛(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 Farmer John变得非常懒,他不想再继续维护供奶牛之间供通行的道路.道路被用来连接N个牧场,牧场被连续地编号为1到N.每一个牧场都是 ...

  9. 算法笔记(c++)--回文

    算法笔记(c++)--回文 #include<iostream> #include<algorithm> #include<vector> using namesp ...

  10. 算法笔记(c++)--完全背包问题

    算法笔记(c++)--完全背包和多重背包问题 完全背包 完全背包不同于01背包-完全背包里面的东西数量无限 假设现在有5种物品重量为5,4,3,2,1  价值为1,2,3,4,5  背包容量为10 # ...

随机推荐

  1. catkin

    catkin  ros https://github.com/dirkholz/pcl_online_viewer rosrun  ???

  2. [Training Video - 3] [Java Introduction] [Object Oriented Programming]

    Static and non-Static :  非静态方法(不带static)可以访问静态变量和方法(带static),但是反过来就不行. 类的静态成员(变量和方法)属于类本身,在类加载的时候就会分 ...

  3. TF Boys (TensorFlow Boys ) 养成记(六): CIFAR10 Train 和 TensorBoard 简介

    圣诞节玩的有点嗨,差点忘记更新.祝大家昨天圣诞节快乐,再过几天元旦节快乐. 来继续学习,在/home/your_name/TensorFlow/cifar10/ 下新建文件夹cifar10_train ...

  4. 关于InvokeMethod Activity的异步调用

    讨论地址:http://www.cnblogs.com/foundation/archive/2009/12/17/1626617.html 结论是IsCompleted的设置被忽略,看代码里注释 u ...

  5. awk基础01-基本用法

    什么是awk     awk 是一门解释型的编程语言,支持条件判断,数组.循环等功能.可用于文本处理.输出格式化的文本信息.执行数学运算.字符串等操作.     awk在处理文件时按行进行逐行处理,即 ...

  6. 还原bak到localdb的问题:The logical database file cannot be found ldf

    主要环境相关因素:win7,ms sql 2012,ms localdb,msms 2012. 步骤: 1,让DBA给一个bak文件到本地来做测试,DBA按自己的工作流程得到bak文件. 2,在msm ...

  7. Android-有序广播明确指定接收者

    在上一篇博客,Android-有序广播是可以中断的,介绍了 有序广播是可以中断的,但还有一种例外情况:明确指定接收者的有序广播是无法中断的,一定会发送到指定的接收者 AndroidManifest.x ...

  8. [C#] ??雙問號的意思及用法

    int? x = null; int y = x ?? -1; 上面二行中,第一行是將x變數放入null,為什麼int能放null,可以參考另一篇文章http://charleslin74.pixne ...

  9. WIN7或2008远程连接特别慢的解决方法 【转】

    方法一. 原因在于从vista开始,微软在TCP/IP协议栈里新加了一个叫做“Window Auto-Tuning”的功能.这个功能本身的目的是为了让操作系统根据网络的实时性能,(比如响应时间)来动态 ...

  10. Selenium框架切换-----Selenium快速入门(七)

    上一篇说了窗口的切换,本篇说说框架的切换. 切换框架:是指切换html中的iframe标签元素或者frame标签元素,注意,并不包括frameset 以下是常用的方法: 方法 说明 WebDriver ...