PAT1063. Set Similarity (25)
来自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;
}
PAT1063. Set Similarity (25)的更多相关文章
- 1063. Set Similarity (25)
1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- 【PAT】1063. Set Similarity (25) 待改进
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the ...
- 1063 Set Similarity (25分)
Given two sets of integers, the similarity of the sets is defined to be /, where Nc is the number ...
- PAT-1063 Set Similarity (set集合)
1063. Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*1 ...
- PAT 1063 Set Similarity (25)
题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT甲题题解-1063. Set Similarity (25)-set的使用
题意:两个整数集合,它们的相似度定义为:nc/nt*100%nc为两个集合都有的整数nt为两个集合一共有的整数注意这里的整数都是各不相同的,即重复的不考虑在内.给出n个整数集合,和k个询问,让你输出每 ...
- A1063 Set Similarity (25 分)
一.技术总结 这个题目是属于set容器的内容,使用可以减少很多代码量 开始试过在同一个for循环中定义两个auto,结果编译通不过,有时候构思很重要,就比如这一题,开始我是一个一个去加,而代码中是,先 ...
随机推荐
- 云计算之路:2009年Xen一个补丁背后那不为人知的故事
仔细阅读了http://www.cnblogs.com/cmt/p/3729386.html这篇关于xen的博文,这篇博文写的挺赞的,分析的也很细致,涉及到4年前的一个patch的故事.在讲这个故事之 ...
- mysql中给表添加字段
添加字段: 格式:alter table 表名 add 字段名 字段类型 ; 如:给表stu_info 添加一个字段type,类型为varchar(30) alter table stu_info a ...
- 深度扫盲O2O
http://www.ftchinese.com/interactive/5038?i=3 http://www.ftchinese.com/interactive/5038?i=3
- 网络编程4 网络编程之FTP上传简单示例&socketserver介绍&验证合法性连接
今日大纲: 1.FTP上传简单示例(详细代码) 2.socketserver简单示例&源码介绍 3.验证合法性连接//[秘钥加密(urandom,sendall)(注意:中文的!不能用)] 内 ...
- visual studio 2017 编译v140 TRACKER : error TRK0005: Failed to locate: "CL.exe". 系统找不到指定的文件
原因可能是vs2017中配置v140 的编译命令路径有问题 解决方案: 用vs2017的在线安装程序,选择修改 进去后选择单个组建,在编译器.生成工具和运行时里面把vc++2015.3…… 打钩的取消 ...
- SOE不能进入断点调试
一.前言 任何程序开发,如果不能进入断点调试,是非常的痛苦的. 如果有过SOE开发经验的人都知道,SOE开发过程中调试是非常麻烦的.任何在SOE开发模板中的修改都需要重新编译工程,重新生成.soe 文 ...
- 深入Redis内部-Redis 源码讲解(转)
Redis作为 NoSQL 数据库的杰出代表,一直广受关注,其轻量级的敏捷架构,向来有存储中的瑞士军刀之称.下面推荐的一篇文章,从源码的角度讲解了Redis 的整个工作流程,是了解 Redis 流程的 ...
- redis中默认有多少个哈希槽?
Redis 集群中内置了 16384 个哈希槽,当需要在 Redis 集群中放置一个 key-value时,redis 先对 key 使用 crc16 算法算出一个结果,然后把结果对 16384 求余 ...
- Flask(5)- Flask-Session组件、WTForms组件、数据库连接池(POOL)
一.Flask-Session 我们使用过flask内置的session,知道它是把session存放在浏览器,即客户端.今天要学习的flask-session是flask的第三方组件,看一下它和fl ...
- Django的模型层(2)- 多表操作(上)
一.创建模型 例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者模型之间是一对一(on ...