【算法笔记】A1063 Set Similarity
Given two sets of integers, the similarity of the sets is defined to be /, where Nc is the number of distinct common numbers shared by the two sets, and Nt 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的更多相关文章
- 学习Java 以及对几大基本排序算法(对算法笔记书的研究)的一些学习总结(Java对算法的实现持续更新中)
Java排序一,冒泡排序! 刚刚开始学习Java,但是比较有兴趣研究算法.最近看了一本算法笔记,刚开始只是打算随便看看,但是发现这本书非常不错,尤其是对排序算法,以及哈希函数的一些解释,让我非常的感兴 ...
- 算法笔记--数位dp
算法笔记 这个博客写的不错:http://blog.csdn.net/wust_zzwh/article/details/52100392 数位dp的精髓是不同情况下sta变量的设置. 模板: ]; ...
- 算法笔记--lca倍增算法
算法笔记 模板: vector<int>g[N]; vector<int>edge[N]; ][N]; int deep[N]; int h[N]; void dfs(int ...
- 算法笔记--STL中的各种遍历及查找(待增)
算法笔记 map: map<string,int> m; map<string,int>::iterator it;//auto it it = m.begin(); whil ...
- 算法笔记--priority_queue
算法笔记 priority_queue<int>que;//默认大顶堆 或者写作:priority_queue<int,vector<int>,less<int&g ...
- 算法笔记--sg函数详解及其模板
算法笔记 参考资料:https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html sg函数大神详解:http://blog.csdn.net/l ...
- 算法笔记——C/C++语言基础篇(已完结)
开始系统学习算法,希望自己能够坚持下去,期间会把常用到的算法写进此博客,便于以后复习,同时希望能够给初学者提供一定的帮助,手敲难免存在错误,欢迎评论指正,共同学习.博客也可能会引用别人写的代码,如有引 ...
- 算法笔记_067:蓝桥杯练习 算法训练 安慰奶牛(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 Farmer John变得非常懒,他不想再继续维护供奶牛之间供通行的道路.道路被用来连接N个牧场,牧场被连续地编号为1到N.每一个牧场都是 ...
- 算法笔记(c++)--回文
算法笔记(c++)--回文 #include<iostream> #include<algorithm> #include<vector> using namesp ...
- 算法笔记(c++)--完全背包问题
算法笔记(c++)--完全背包和多重背包问题 完全背包 完全背包不同于01背包-完全背包里面的东西数量无限 假设现在有5种物品重量为5,4,3,2,1 价值为1,2,3,4,5 背包容量为10 # ...
随机推荐
- dedecms导出csv文件
1.mshd_orderlist.tpl <form id="frm" method="GET" action="mshd_orderlist. ...
- [Jenkins]怎样自定义发出邮件的 From Email Address 和 From Name
在Jenkins上建了一个执行SoapUI的task,想要自定义发送邮件的地址和姓名,怎么办呢? 在Editable Email Notification里面添加Pre-send Script 脚本如 ...
- android模拟按键问题总结[使用IWindowManager.injectKeyEvent方法](转)
http://blog.csdn.net/xudongdong99/article/details/8857173 Android上面TreeView效果 http://blog.csdn.net/g ...
- 获取iPod library中的媒体文件
[获取iPod library中的媒体文件] The Media Player framework provides facilities for playing movie, music, audi ...
- 23 DesignPatterns学习笔记:C++语言实现 --- 2.7 Proxy
23 DesignPatterns学习笔记:C++语言实现 --- 2.7 Proxy 2016-07-18 (www.cnblogs.com/icmzn) 模式理解
- linux squid
iptables -F iptables -F -t nat 网关 iptables -t nat -A POSTROUTING -s 10.1.0.0/16 -o eth0 -j MASQUERAD ...
- [Erlang24]使用zotonic搭建网站记录
zotonic的搭建网站(blog)记录: zotonic:用Erlang做的一个web 框架: 和wordpress 类似,但是官网称比PHP CMS要快10倍以上 先看看我的成果:正弦 ...
- solr分词一:mmseg4j
刚接触Lucene2.x和Solr2.x的时候,谈到中文分词,会让我立即想到用庖丁中文分词,庖丁中文分词因巨大的中文词库以及支持不限制个数的用户自定义词库,而且是纯文本格式,一行一词,使用后台线程检测 ...
- shell脚本修改文件
https://blog.csdn.net/qq_37674858/article/details/80066264 2.2 使用sed命令对文件中的字符替换 例如:将aaaa字符串修改为bbbb [ ...
- web api 跨域问题的解决办法
在APP_Start文件夹下面的WebApiConfig.cs文件夹配置跨域 public static class WebApiConfig { public static void Registe ...