代码:

#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轮换

    switch_source()用于获取文本信息rewrite_source()用于将信息顺序轮换,其参数times表示要轮换多少次, def switch_source(): tmp = [] wit ...

  2. 使用TensorRT加速yolo3

    一.TensorRT支持的模型: TensorRT 直接支持的model有ONNX.Caffe.TensorFlow,其他常见model建议先转化成ONNX.总结如下: 1 ONNX(.onnx) 2 ...

  3. python3.x Day4 模块!!

    json and pickle模块 用途是为了持久化信息,这种持久化方式可以和其他程序语言兼容,一般都支持json,json只能持久化数据,pickle是python特有的方式,可以持久化所有信息和数 ...

  4. chrome最强大的浏览器插件推荐,只要你会用其他的插件你可以删除了

    我们在学习和工作中经常会需要用到各种各样不同需求的插件,结果chrome插件越装越多,chrome浏览器也越来越慢!有时候链我们自己都懵圈了,一时间都想不起来这个插件是干什么用的.更可气的是,很多时候 ...

  5. Python之爬虫-段子网

    Python之爬虫-段子网 https://ishuo.cn #!/usr/bin/env python # -*- coding:utf-8 -*- import re import request ...

  6. 爬虫框架urllib 之(二) --- urllib基础

    urllib 官方文档:https://docs.python.org/zh-cn/3/library/urllib.html urllib介绍 Urllib是python内置的HTTP请求库,是py ...

  7. 数据导出Excel,动态列

    今天碰到一个需求,要求将用户回答的问卷及问题导出Excel表格,问卷对应的问题数量不一致,需要动态添加列表头,简单记录. 要导出Excel需要添加poi.jar包 用户-问卷实体(固定列): pack ...

  8. [HAOI2011]Problem b 题解

    题目大意: 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y)=k. 思路: 设f(k)为当1≤x≤n,1≤y≤m,且n≤m,使gcd(x,y)=k的数对 ...

  9. POJ 3348 最直接的凸包问题

    题目大意: 给定一堆树的点,找到能组合成的最大面积,一个物体占50面积,求最多放多少物体 #include <cstdio> #include <cstring> #inclu ...

  10. hdu 1698区间延迟更新

    #include<stdio.h> #define N 100100 struct node { int x,y,yanchi; }a[N*4];//注意数组范围 void build(i ...