Sleep Buddies
Sleep Buddies
2.0 s
256 MB
standard input
standard output
It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. It is common to sleep in pairs, so that if anything were to happen during the night people could aid each other.
To decide who is a suitable candidate to sleep with whom, the leaders of GEMA asked everyone to answer a questionnaire about attributes they desire their partner to have from a list of M possible items.
To choose the pairs, GEMA uses the Jaccard index between the desired attributes of both persons. The Jaccard index for two sets A andB is defined as , that is, the size of the intersection between A and B divided by the size of their union. They allow a pair to be formed if the Jaccard index of the two attribute sets for the pair is at least K.
Thanks to GEMA, there are too many people living on Mars these days. Help the high commanders decide how many allowed pairs there are out of the N people living there.
The input begins with two integers, N and M (1 ≤ N ≤ 105, 1 ≤ M ≤ 10), the number of people on Mars and the number of possible attributes on the questionnaire.
Then follow N lines, each beginning with an integer Q (1 ≤ Q ≤ M), the number of desired attributes on the list of the i-th person. Then follow Q integers q (1 ≤ q ≤ M), encoding these attributes. There numbers are all different.
The last line of input contains a real number K (0 ≤ K ≤ 1), the minimum required Jaccard index for a pair.
Output the number of pairs that are allowed.
Examples
2 5
2 1 3
5 3 1 5 4 2
0.66489
0
3 1
1 1
1 1
1 1
0.85809
output
3
//题意: n 个集合,全集为 1 -- m 的整数,然后一个比率 k , 然后问,每两个的集合交集元素个数除并集元素个数大于 k 的个数有多少
//注意到,全集 m 非常小,所以,可以用二进制来表示某个数有没有,这样,每个数都能代表一个集合,最多也就 2^10 = 1024 个
统计数量,暴力二重循环计数即可,又犯了个错,浮点数的大于等于,一定要理解!!!
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define LL long long
# define pr pair
# define mkp make_pair
# define lowbit(x) ((x)&(-x))
# define PI acos(-1.0)
# define INF 0x3f3f3f3f3f3f3f3f
# define eps 1e-
# define MOD inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
# define MX
/**************************/ int n,m;
int st[MX]; LL C(LL a,LL b)
{
if (b<) return ;
return b*(b-)/;
} double gai(int a,int b)
{
int all = ;
int jiao =;
for (int i=;i<m;i++)
{
if ( (a&(<<i)) || (b&(<<i)) ) all++;
if ( (a&(<<i)) && (b&(<<i)) ) jiao++;
}
return (jiao*1.0)/all;
} int main()
{ while (scanf("%d%d",&n,&m)!=EOF)
{
memset(st,,sizeof(st));
for (int i=;i<=n;i++)
{
int num;
scanf("%d",&num);
int sb=;
for (int j=;j<=num;j++)
{
int x;
scanf("%d",&x);
sb = (sb ^ (<<(x-)));
}
st[sb]++;
}
double p;
scanf("%lf",&p); LL ans = ;
int ut = (<<m);
for (int i=;i<ut;i++)
{
for (int j=i;j<ut;j++)
{
if (gai(i,j)-p>-eps)
{
if (i==j) ans = ans+C(,st[i]);
else ans = ans+((LL)st[i])*st[j];
}
}
}
cout<<ans<<endl;
}
return ;
}
Sleep Buddies的更多相关文章
- 2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys
Gym101063C-Sleep Buddies It is nighttime in the Earth Colony on Mars and everyone is getting ready t ...
- uva 12356 Army Buddies 树状数组解法 树状数组求加和恰为k的最小项号 难度:1
Nlogonia is fighting a ruthless war against the neighboring country of Cubiconia. The Chief General ...
- Codeforces Gym101063 C.Sleep Buddies (2016 USP-ICMC)
C.Sleep Buddies It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. ...
- PyQt学习随笔:Qt Designer的Edit Buddies功能
在Qt Designer的Edit菜单下有个Edit Buddies(编辑伙伴关系)子菜单,该菜单的作用是将一个Label与其他控件关联起来,当Label控件设置了快捷键时,通过Label的快捷键就可 ...
- uva 12356 Army Buddies
简单的并查集应用. #include<stdio.h> #include<string.h> #include<math.h> #include<algori ...
- Java:泛型基础
泛型 引入泛型 传统编写的限制: 在Java中一般的类和方法,只能使用具体的类型,要么是基本数据类型,要么是自定义类型.如果要编写可以应用于多种类型的代码,这种刻板的限制就会束缚很多! 解决这种限制的 ...
- 黑马----JAVA泛型基础
黑马程序员:Java培训.Android培训.iOS培训..Net培训 JAVA范型-基础 一.泛型的概念 1.实现了参数化类型 2.用于编写可应用于多种类型的代码,即所编写的代码可应用于许多许多的类 ...
- java 泛型编程学习
先发布,以后有空再修改... 第一次看到<java核心技术卷一>中关于泛型这部分的时候感觉很复杂,似乎有说不完的约束条件,让人难以理解.当时只是囫囵吞枣般过了一遍,也没有看出个什么来.现在 ...
- 《程序设计教学法--以Java程序设计为例》
<程序设计教学法--以Java程序设计为例> 当老师上的第一门课就是<Java程序设计>,工作以来,断断续续上了近十次课了吧.十几年来,教材.课程内容.教学方法.教学手段不断改 ...
随机推荐
- 04-常见内存错误以及valgrind使用
04-常见内存错误以及valgrind使用 代码段: 仅仅读数据,因此对这一部分的数据.试图写仅仅读数据,这个在编译的时候基本上能够检測. 数据段/BSS段: 未初始化直接訪问,即使没有显示初始化,仍 ...
- Drawing-Order-Of-meshes-and-sprites
Sprite 和 Mesh Render 共存 [CanEditMultipleObjects] [CustomEditor(typeof(MeshRenderer))] public class M ...
- pydensecrf安装报错1、UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 29: invalid start byte2、 LINK : fatal error LNK1158: 无法运行“rc.exe” error: command 'D:\\software\\vs2015\\VC\\BIN
pydensecrf安装报错 1.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 29: invalid st ...
- node-webkit 开发环境搭建
node-webkit支持的操作系统类型: Linunx:32bit / 64bit Windows: win32 Mac:32bit,10.7+ 开发环境 1,根据自己的操作系统下载响应的nw二进制 ...
- Nginx通过CORS实现跨域(转)
如果前端有nginx方向代理,跨域配置在前端反向代理nginx上 要做跨域域名限制 什么是CORS CORS是一个W3C标准,全称是跨域资源共享(Cross-origin resource shari ...
- python判断文件是否存在目录中
##支持排除文件和目录#!/usr/bin/python #coding:utf-8 import os def list_file(file_name): data = [] file_name = ...
- linux系统日志报错
使用journalctl -xe命令时报错: Error was encountered while opening journal files: Input/output error 日志文件损坏了 ...
- eclipse进行远程调试教程,轻松搞定生产环境问题
首先你本地Eclipse上要有和部署在远程服务器一至的项目,否则debug的时候会出现代码行错位,难以达到debug的效果.例如:如果你本地的代 码加了行,修改了,或减了一行.而远程服务器上的项目没有 ...
- Html打印需要内容块(Js实现)
首先在head里面加入下面一段js代码: function preview(oper) { ) { bdhtml = window.document.body.innerHTML; //获取当前页的h ...
- C语言基础(20)-文件操作(fopen,getc,fclose)
一.文件操作 读文件的顺序: 1.先打开文件 2.读写文件 3.关闭文件 1.1 fopen FILE *fopen( const char *path, const char *mode ); 函数 ...