https://www.patest.cn/contests/gplt/L2-005

题解:直接set的count函数

坑 :要用容斥原理算两个集合的并,否则超时。(我还以为要打表呢)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include<stack>
#include<set>
#include<string.h>
#include<list>
#define pb push_back
#define mp make_pair
#define _for(i, a, b) for (int i = (a); i<(b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 50 + 5;
set<int> s[N];
int main() {
int n;
cin >> n;
_for(i, 1, n+1) {
int k;
cin >> k;
_for(j, 0, k) {
int x;
cin >> x;
s[i].insert(x);
}
}
int q;
/*_for(i,1,n)
_for(j, i+1, n + 1) {
for (auto t : s[i]) if (s[j].count(i)) tc[i][j]++;
tt[i][j] = s[i].size() + s[j].size() - 2*tc[i][j];
}*///写了一半感觉容斥定理可能能ac
cin >> q;
_for(i, 0, q) {//2000*4000 8e6 tle;
int x, y;
cin >> x >> y;
float nc=0, nt=0;
set<int> t;
for (auto t1 : s[x]) { if (s[y].count(t1)) nc++; }
//for (auto t2 : s[y]) {t.insert(t2);}
nt = s[x].size()+s[y].size()-nc;
printf("%.2lf%%\n", nc / nt * 100);
}
system("pause");
}

CCCC L2-005. 集合相似度的更多相关文章

  1. 团体程序设计天梯赛-练习集L2-005. 集合相似度

    L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...

  2. L2-005. 集合相似度(STL)*

    L2-005. 集合相似度 参考博客 #include<cstdio> #include<set> #include<cstdlib> using namespac ...

  3. pat 集合相似度

    L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...

  4. L2-005. 集合相似度(set使用)

    L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...

  5. 天梯杯 L2-005. 集合相似度

    L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...

  6. PTA 7-9 集合相似度(STL之set初体验)

    7-9 集合相似度(25 分) 给定两个整数集合,它们的相似度定义为:N​c​​/N​t​​×100%.其中N​c​​是两个集合都有的不相等整数的个数,N​t​​是两个集合一共有的不相等整数的个数.你 ...

  7. L2-005 集合相似度 (25 分) (STL——set)

    链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805070149828608 题目: 给定两个整数集合,它们的相似度 ...

  8. PAT L2-005 集合相似度(模拟集合set)

    给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...

  9. 天梯赛 L2-005 集合相似度 (set容器)

    给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...

随机推荐

  1. 5 -- Hibernate的基本用法 --4 1 创建Configuration对象

    org.hibernate.cfg.Configuration实例代表了应用程序到SQL数据库的配置信息,Configuration对象提供了一个buildSessionFactory()方法,该方法 ...

  2. argc和argv

    ARGc和ARGv中的ARG指的是"参数"(外语:ARGuments, argument counter 和 argument vector ) argc: 整数,用来统计你运行程 ...

  3. 执行RF设置顶层测试套件的描述说明

    场景1:通过pybot命令更新套件层描述 命令:pybot -D 套件层描述 -D --doc documentation 设置顶层测试套件的描述说明.说明中下划线将转换为空格, 并且他可能包含简单的 ...

  4. SQL筛选出同一学科的时间最新的记录

    1.建表语句 CREATE TABLE `score` ( `id` ) NOT NULL AUTO_INCREMENT, `student_id` ) ' COMMENT '学生表ID', `nam ...

  5. MHL相关资源链接

    http://www.mhlconsortium.org/ 消费者网站: www.meetmhl.com采用者网站:www.mhltech.org 博客http://blog.sina.com.cn/ ...

  6. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing ___Error Installing APK

    一 : 根据以下路径,找到Instant Run中的选项         File —— Settings——Build,Execution,Deployment——Instant Run       ...

  7. iOS9下App Store新应用提审攻略

    博文转载 CocoaChina 文/文公子 公子在第十讲中提到应用更新时需要注意的细节和苹果便捷通道的利用.今天,公子将进一步深扒iTunes Connect的面纱,为大家呈现新应用在提审前需要准备的 ...

  8. Git学习之Git 暂存区

    ============================= 修改文件后是否可以直接提交 ============================ (1) 向文件中追加一行内容  $ echo &quo ...

  9. Spark学习笔记--Linux安装Spark集群详解

    本文主要讲解如何在Linux环境下安装Spark集群,安装之前我们需要Linux已经安装了JDK和Scala,因为Spark集群依赖这些.下面就如何安装Spark进行讲解说明. 一.安装环境 操作系统 ...

  10. sencha touch 2.2 为list PullRefresh插件添加refreshFn方法

    sencha touch 2.2 list PullRefresh插件没有refreshFn方法 但是我们又需要他,所以需要自行扩展 代码如下 /** * 重写下拉刷新插件,以支持refreshFn事 ...