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,结果编译通不过,有时候构思很重要,就比如这一题,开始我是一个一个去加,而代码中是,先 ...
随机推荐
- php获取本地IP
function get_local_ip() { $preg = "/\A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\.){3 ...
- instanceof和isInstance(Object obj) 和isAssignableFrom(Class cls)的区别和联系
instanceof和isInstance(Object obj) 和isAssignableFrom(Class cls)的区别和联系 编程的时候可能会遇到一个不知道它属于哪个类的 ...
- Exchange Version and UpdateRollups
Exchange Server 2010 Product name Build number Date KB Microsoft Exchange Server 2010 RTM 14.0.639.2 ...
- Spring MVC http请求地址映射(三)
Spring MVC框架通过扫描将带有@Controller的类中的@RequestMapping的方法进行映射,然后调用映射的方法处理请求,这个分发过程默认是由DispaterServlet处理的. ...
- python类的相关知识第一部分
一.类的相关概念 (1).什么是类 具有同种属性的对象称为类,是个抽象的概念.比如说:汽车.人.狗.神: (2).什么是对象或实例 日常生活中的所有东西都是对象,是类的实例化.比如说:推土车是汽车的实 ...
- 解决chrome在ubuntu+root模式下打不开的问题
chrome在ubuntu root模式下打不开 双击图标,chrome打不开了: 解决办法: 查看一下打开chrome浏览器的命令是什么,右键properties 发现是chromium-brows ...
- onchange事件可以使用于: <input>, <select>, 和 <textarea>。
onchange 事件会在域的内容改变时发生. onchange 事件也可用于单选框与复选框改变后触发的事件.
- 海报工厂之(一)android 如何给图片添加水印和文字
在Android中如何给图片添加水印,下面截取了部分核心代码,仅供参考: /** * 获取图片缩小的图片 * @param src * @return */ ...
- 001-es6变量声明、解构赋值、解构赋值主要用途
一.基本语法 1.1.声明变量的六种方法 参看地址:http://es6.ruanyifeng.com/#docs/let let:局部变量,块级作用域,声明前使用报错 var:全局变量,声明前使用 ...
- c++ 11 bind function
Year 2011陈 良乔C++11 FAQ std::function 和 std::bind 标准库函数bind()和function()定义于头文件中(该头文件还包括许多其他函数对象),用于处理 ...