pat(A) 1063. Set Similarity(STL)
代码:
#include<cstdio>
#include<cstring>
#include<set>
using namespace std; set<int> st[55]; int main()
{
int n,m,k;
while(scanf("%d",&n)==1)
{
double dp[100][100];
for(int i=0; i<55; i++)
{
for(int j=0; j<55; j++)
{
dp[i][j]=-1.0;
}
}
for(int i=1; i<=n; i++)
{
st[i].clear();
scanf("%d",&m);
for(int j=0; j<m; j++)
{
int x;
scanf("%d",&x);
st[i].insert(x);
}
}
scanf("%d",&k);
while(k--)
{
int x,y;
char c='%';
scanf("%d%d",&x,&y);
if(st[x].size()==0&&st[y].size()!=0)
{
printf("0.0");
printf("%c\n",c);
continue;
}
if(st[x].size()!=0&&st[y].size()==0)
{
printf("0.0");
printf("%c\n",c);
continue;
}
if(x==y)
{
printf("100.0");
printf("%c\n",c);
continue;
}
set<int>::iterator it;
int cnt=0;
//printf("%lf\n",dp[x][y]);
if(dp[x][y]==-1.0)
{
//printf("-----\n");
for(it=st[x].begin(); it!=st[x].end(); it++)
{ if(st[y].find(*it)!=st[y].end())
cnt++;
}
dp[x][y]=cnt*1.0/(st[x].size()+st[y].size()-cnt);
} //printf("%d\n",cnt);
printf("%.1lf",dp[x][y]*100);
//char c='%';
printf("%c",c);
printf("\n");
}
}
return 0;
}
pat(A) 1063. Set Similarity(STL)的更多相关文章
- 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 ...
- PAT 甲级 1063 Set Similarity
https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of inte ...
- PAT 1063. Set Similarity
1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...
- PAT 1063 Set Similarity[比较]
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...
- 1063 Set Similarity——PAT甲级
1063 Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*10 ...
- 1063. Set Similarity (25)
1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 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 ...
随机推荐
- Less用法注意事项
(1)引入顺序 引入你的 .less 样式文件的时候要设置 rel 属性值为 “stylesheet/less”: <link rel="stylesheet/less" t ...
- JavaSE-17 泛型
学习要点 泛型接口 泛型类 泛型方法 多参数泛型类 泛型类的继承 泛型的定义 允许在定义类.接口.方法时使用类型形参,类型形参将会在声明变量.创建对象或者调用方法时候动态指定. 泛型接口 1 定义 ...
- canvas学习--准备
一)canvas标签 属性: 1.width 和 height 控制canvas宽高: 2.style添加基本样式 3.class,id属性 4.标签内添加一行文本,主要用于浏览器不支持canvas标 ...
- SVN CommandLine
要是SVN命令行用不了的话: 1.SVN装了没? 2.SVN安装时,选项“command line client tools”选了没. 检出: svn checkout [-depth ARG] [- ...
- Python之禅 吾心笃定
自从3月19日到现在已经学习python 19天了,博客园也注册8天了.之所以一直没有急着分享学习中的知识是因为我觉得学习一道应该从心开始,所以第一篇随笔不应该说python的知识,而应该说学习心态和 ...
- Windows下Eclipse+PyDev安装Python开发环境
.简介 Eclipse是一款基于Java的可扩展开发平台.其官方下载中包括J2EE方向版本.Java方向版本.C/C++方向版本.移动应用方向版本等诸多版本.除此之外,Eclipse还可以通过安装插件 ...
- linux下的文档处理及tar命令
1.使用cat命令进行纵向合并 使用‘>’是将左边的内容覆盖到右边 使用‘>>’是将左边的内容追加到右边文档中 还可使用‘>’将不同文件进行合并 2.管道符‘|’统计行数 使用 ...
- 【BZOJ 1202】 [HNOI2005]狡猾的商人(枚举区间也可行)
题链:http://www.lydsy.com/JudgeOnline/problem.php?id=1202 其实也可以不使用加权并查集,通过画图可以发现,一个长区间和其包含的区间能够算出一个新区间 ...
- 56. spring boot中使用@Async实现异步调用【从零开始学Spring Boot】
什么是"异步调用"? "异步调用"对应的是"同步调用",同步调用指程序按照定义顺序依次执行,每一行程序都必须等待上一行程序执行完成之后才能执 ...
- [luoguP2672] 推销员(贪心 + 树状数组 + 优先队列)
传送门 贪心...蒟蒻证明不会... 每一次找最大的即可,找出一次最大的,数列会分为左右两边,左边用stl优先队列维护,右边用树状数组维护.. (线段树超时了....) 代码 #include < ...