CCCC L2-005. 集合相似度
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. 集合相似度的更多相关文章
- 团体程序设计天梯赛-练习集L2-005. 集合相似度
L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...
- L2-005. 集合相似度(STL)*
L2-005. 集合相似度 参考博客 #include<cstdio> #include<set> #include<cstdlib> using namespac ...
- pat 集合相似度
L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...
- L2-005. 集合相似度(set使用)
L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...
- 天梯杯 L2-005. 集合相似度
L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*1 ...
- PTA 7-9 集合相似度(STL之set初体验)
7-9 集合相似度(25 分) 给定两个整数集合,它们的相似度定义为:Nc/Nt×100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你 ...
- L2-005 集合相似度 (25 分) (STL——set)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805070149828608 题目: 给定两个整数集合,它们的相似度 ...
- PAT L2-005 集合相似度(模拟集合set)
给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...
- 天梯赛 L2-005 集合相似度 (set容器)
给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...
随机推荐
- 【Oracle】强制关闭会话
select sid, serial# from V$session where sid in (select sid from v$LOCK where TYPE in ('TM','TX')); ...
- XSS payload 大全
收集的一些XSS payload,主要分为五大类,便于查阅. #第一类:Javascript URL <a href="javascript:alert('test')"&g ...
- Explaining Delegates in C# - Part 5 (Asynchronous Callback - Way 2)
In this part of making asynchronous programming with delegates, we will talk about a different way, ...
- Win10 取消桌面快捷键图标
新建文本文档 --- 写入如下内容 --- 改名为 .bat 并运行 @echo off color 2 reg delete HKCR\lnkfile /v IsShortcut /f reg de ...
- [Android] Nexus 7 二代连接 Windows 7
Android 设备的三大 USB 连接模式 MTP:Media Transfer Protocol - 媒体传输协议,Windows 下最常见的连接模式,是微软一种可以管理便携存储设备的协议.MTP ...
- 关于GDI+的一些使用基础设置
一.新建一个MFC的单文档工程,例如工程名字叫GDIPLUSTEST1. 二.在工程的stdafx.h头文件中添加入 #include "gdiplus.h" using name ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)
题目链接:http://www.codeforces.com/problemset/problem/281/A题意:将一个英文字母的首字母变成大写,然后输出.C++代码: #include <c ...
- 《转》win7 安装ujson 出现的“error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27”
本文转载自http://blog.csdn.net/Tilyp/article/details/72842800?locationNum=2&fps=1 我的python环境是 D:\work ...
- 在MyEclipse(2015)中上传项目到github的步骤(很详细)
(图文)在MyEclipse(2015)中上传项目到github的步骤(很详细) git|smartGit使用详解 SmartGit使用教程
- oracle闪回数据
方法一 数据删除了: select * from t_test as of timestamp to_timestamp('2011-10-25 13:45:00','yyyy-mm-dd hh2 ...