代码:

#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. python appium自动化,走过的坑

    使用的夜神模拟器,使用android5.1.1 第一坑:使用的android7.1.2,刚开始写好了登录的代码,需要的是滑屏进入到登录界面,结果运行的时候,没有自动滑屏就报错:因为运行时,报了一个进程 ...

  2. Myeclipse中dubug调试出现参数显示的框

    1.步骤: window>show view>variables 结果:

  3. 对拍 bat命令快速模板

    对拍.bat @echo off :loop maker.exe > in.in wq.exe < in.in > out.out std.exe < in.in >st ...

  4. Python学习-初始列表

    初始列表 列表中的排放是没有顺序的并且可以被修改 在列表中你可以放入任何的元素类型.字符串,数字,布尔值等等,甚至还可以进行列表的嵌套 列表的注意特征:用中括号包围,中间用逗号分隔开 list = [ ...

  5. [Python3网络爬虫开发实战] 1.4.1-MySQL的安装

    MySQL是一个轻量级的关系型数据库,本节中我们来了解下它的安装方式. 1. 相关链接 官方网站:https://www.mysql.com/cn 下载地址:https://www.mysql.com ...

  6. linux命令 dig-域名查询工具

    博主推荐:更多网络测试相关命令关注 网络测试  收藏linux命令大全 dig命令是常用的域名查询工具,可以用来测试域名系统工作是否正常. 语法 dig(选项)(参数) 选项 @<服务器地址&g ...

  7. 嵌入式linux启动信息完全注释

    嵌入式linux启动信息完全注释 from:http://www.embedlinux.cn/ShowPost.asp?ThreadID=377 摘要 我们在这里讨论的是对嵌入式linux系统的启动过 ...

  8. 怎样提高ES集群的稳定性?

    别挂master节点. 稳定性:独立的master节点, 独立的协调节点 > master兼职协调节点 > master兼职数据节点 > master 兼职协调 + 数据节点. cl ...

  9. mysql ab主从复制出错及解决过程

    一.mysql主从服务器报错描述:Slave_IO_Running=NO,Slave_SQL_Running=YES,Last_Errno=0 mysql slave stop ; mysql sla ...

  10. HDU 2147 找规律博弈

    题目大意: 从右上角出发一直到左下角,每次左移,下移或者左下移,到达左下角的人获胜 到达左下角为必胜态,那么到达它的所有点都为必败态,每个点的局势都跟左,下,左下三个点有关 开始写了一个把所有情况都计 ...