代码:

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

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

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

  3. PAT 甲级 1063 Set Similarity

    https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of inte ...

  4. PAT 1063. Set Similarity

    1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...

  5. PAT 1063 Set Similarity[比较]

    1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...

  6. 1063 Set Similarity——PAT甲级

    1063 Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*10 ...

  7. 1063. Set Similarity (25)

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

  8. PAT 1063 Set Similarity (25)

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

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

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

随机推荐

  1. jQuery动态移除和绑定事件

    function bindEvent() { //移除绑定事件 $('.btnsp').unbind('click'); //绑定事件 $('.btnsp').bind('click', functi ...

  2. 微信小程序(template的使用)

    小程序的template是一个模版功能,在创建一个template后,其他的页面可以引用,相比component较简单.方便! template只需要两个文件,一个wxss文件和wxml文件,也只有这 ...

  3. 08私有化、MRO顺序

    一. 私有化 1)xx: 公有变量 2)_x: 单前置下划线,私有化属性或方法,from somemodule import *禁止导入,类对象和子类可以访问 3)__xx:双前置下划线,避免与子类中 ...

  4. Java中9大内置基本数据类型Class实例和数组的Class实例(转载)

    https://www.jianshu.com/p/58976c8bf1e1

  5. [Python3网络爬虫开发实战] 6.3-Ajax结果提取

    这里仍然以微博为例,接下来用Python来模拟这些Ajax请求,把我发过的微博爬取下来. 1. 分析请求 打开Ajax的XHR过滤器,然后一直滑动页面以加载新的微博内容.可以看到,会不断有Ajax请求 ...

  6. [Python3网络爬虫开发实战] 1.7.2-mitmproxy的安装

    mitmproxy是一个支持HTTP和HTTPS的抓包程序,类似Fiddler.Charles的功能,只不过它通过控制台的形式操作. 此外,mitmproxy还有两个关联组件,一个是mitmdump, ...

  7. element-UI 多表单重置的时候的坑

    问题细化一下是这样的:比如我有一个用来修改数据的表单,第一条数据是{name: 'Xixi', age: 12},打开表单后就有两个输入框分别填的是Xixi和12,此时我修改Xixi为Haha,调用t ...

  8. 【转】ASP.NET MVC 4 RC的JS/CSS打包压缩功能

    原文链接:http://www.cnblogs.com/shanyou/archive/2012/06/22/2558580.html 打包(Bundling)及压缩(Minification)指的是 ...

  9. node.js里的buffer常见操作,copy,concat等实例讲解

    //通过长度构建的buffer内容是随机的 var buffer=new Buffer(100); console.log(buffer); //手动清空buffer,一般创建buffer不会清空 b ...

  10. Linux下汇编语言学习笔记24 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...