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 ...
随机推荐
- OneinStack 安装 LNMP 切换PHP版本
如果你的环境不是OneinStack安装的 ,可以略过这条博客了 注意:以下所有命令若提示权限不足 请在命令前加 sudo *** ①,首先查看当前已安装的PHP版本,我这里安装了好几个版本,你们可 ...
- DataRow复制一行到另一个DataTable
DataRow复制一行到另一个DataTable 下面两个方法是DataRow复制一行到另一个DataTable的,直接Add会出错“此行已属于另一个表”,其实以前就知道怎么做的,可每次要用到的时 ...
- CF508E Arthur and Brackets
题目大意:给出n对括号,并给出每对括号距离的范围.问能否找到这样一个序列. 题解:好多人都用贪心.这么好的题为什么不搜一发呢? 注意:千万不要在dfs里面更新答案. 代码: #include<c ...
- js在HTML中的三种写法
1.内联样式 内联样式分为两种,一是直接写入元素的标签内部 <html> <title>js样式内联写法</title> <meta http-equiv=& ...
- BNUOJ 1268 PIGS
PIGS Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: 11496 ...
- HDU 4473
题目大意: 给定一个long long 型的数 n,找到一共有多少对a,b,使比n小的某一个数的是a*b的倍数 这样我们可以理解为 存在a*b*c <= n,令 a <= b <= ...
- MySQL:视图、触发器、存储过程、事务
视图: 视图,虚拟表 创建虚拟表: # 语法: # create view 虚拟表名称 as 虚拟表; create view course_and_teacher as select * from ...
- Django:(5)分页器 & forms组件
Django组件:分页器 目录结构: urls.py from django.contrib import admin from django.urls import path from app01 ...
- 【ZJOI2017 Round1练习&BZOJ4774】D3T2 road(斯坦纳树,状压DP)
题意: 对于边带权的无向图 G = (V, E),请选择一些边, 使得1<=i<=d,i号节点和 n − i + 1 号节点可以通过选中的边连通, 最小化选中的所有边的权值和. d< ...
- Linux下汇编语言学习笔记20 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...