来自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. github删除已经push到服务器上的commit的方法

    使用两条指令: git reset --hard <commit_id> git push origin HEAD --force 其中commit_id是你想回到的commit的id(即 ...

  2. js引入script

    引入再删除,节省资源. <!DOCTYPE html> <html> <head lang="en"> <meta charset=&qu ...

  3. git +vs2017 操作手册+目前工作流程图

    分支名称介绍及命名规则: 测试分支:master 线上稳定分支:master-发布分支 功能分支:命名命名规则:V版本号-开发者姓名-功能名. 紧急修复分支:命名规则:fixbug-版本号-具体问题名 ...

  4. JavaWeb项目(SSM)准备工作

    1.新建dynamic web project(Maven project也行) 我用的Eclipse + ssm + mysql 2.准备jar包 整合ssm的包1. springmvc: ...2 ...

  5. Html5-draggable元素拖动

    Html5元素拖动 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. Internet Explorer 9+, Firefox, Opera, Chrome, 和 Safari 支持拖动 ...

  6. Spring MVC 多语言化的实践和学习

    一.主要参考: SpringMVC简单实现国际化/多语言 - CSDN博客 https://blog.csdn.net/u013360850/article/details/70860144/ 二.总 ...

  7. Dart基础学习03--方法的使用

    1.本文主要讲一下Dart中的方法是怎么定义的,下面先看一个简单的例子: void printNumber(num number) { print('The number is $number.'); ...

  8. 使用synergyc共享键鼠

    通常情况下我们经常同时操作两台或者多台电脑, 这样就会存在多个键盘鼠标来回切换的问题. 那么我们主要的目标就是怎么在多个电脑上共享一套键盘鼠标,而且可以轻松的来回切换呢. 网上有很多的解决方案,这里我 ...

  9. 被Chrome下的remove闪了一下腰

    有用户反映说购物车删除不了东西,于是有了下面的测试. 浏览器:ie7 ie8 ie9 chrome 代码: <a href="javascript:" onclick=&qu ...

  10. Spring 框架的 applicationContext.xml 配置文件

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...