来自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)的更多相关文章

  1. 1063. Set Similarity (25)

    1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  2. 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 ...

  3. 【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 ...

  4. 1063 Set Similarity (25分)

    Given two sets of integers, the similarity of the sets is defined to be /, where N​c​​ is the number ...

  5. 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 ...

  6. PAT 1063 Set Similarity (25)

    题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b ...

  7. PAT (Advanced Level) 1063. Set Similarity (25)

    读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...

  8. PAT甲题题解-1063. Set Similarity (25)-set的使用

    题意:两个整数集合,它们的相似度定义为:nc/nt*100%nc为两个集合都有的整数nt为两个集合一共有的整数注意这里的整数都是各不相同的,即重复的不考虑在内.给出n个整数集合,和k个询问,让你输出每 ...

  9. A1063 Set Similarity (25 分)

    一.技术总结 这个题目是属于set容器的内容,使用可以减少很多代码量 开始试过在同一个for循环中定义两个auto,结果编译通不过,有时候构思很重要,就比如这一题,开始我是一个一个去加,而代码中是,先 ...

随机推荐

  1. 【BZOJ2738】矩阵乘法 整体二分

    [BZOJ2738]矩阵乘法 Description 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. Input 第一行两个数N,Q,表示矩阵大小和询问组数: 接下来N行N列 ...

  2. 教程less

    http://lesscss.cn/features/ Overview As an extension to CSS, Less is not only backwards compatible w ...

  3. Debug技巧:条件断点和远程Debug

    一.断点: 1.条件断点 本以为条件断点很难,其实就这样. 二.远程Debug 1.首先看服务器是不是在Debug模式下工作 不是则进行(tomcat/bin/catalina.sh)配置. -Xde ...

  4. Linux下RTL8723BE无线网卡驱动问题解决方法

    的RT723BE这款无线网卡模块真是坑爹,岂止是坑爹,简直就是坑爹...... lspci -vnn 看网卡型号 一.安装问题: sudo apt-get install linux-headers- ...

  5. SPOJ Number of Palindromes(回文树)

    Number of Palindromes Time Limit: 100MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu ...

  6. netty + Protobuf (整合二)

    [正文]Protobuf 消息设计 疯狂创客圈 死磕Netty 系列之12 [博客园 总入口 ] 本文说明 本篇是 netty+Protobuf 实战的第二篇,完成一个 基于Netty + Proto ...

  7. MyBatis 入门(一)

    1. MyBatis 概述 MyBatis 是一个半自动化的持久层框架; 核心SQL,开发人员可以进行优化; SQL和Java编码分开,功能边界清晰,一个专注业务,一个专注数据; JDBC: SQL ...

  8. 报错:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

    Outline SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: trunc ...

  9. python单线程解决并发

    1.单线程解决并发 方式一 import socket import select # 百度创建连接:非阻塞 client1 = socket.socket() client1.setblocking ...

  10. 携程greenlet模块使用

    import greenlet def f1(): print(11) gr2.switch() print(22) gr2.switch() def f2(): print(33) gr1.swit ...