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程序设计>,工作以来,断断续续上了近十次课了吧.十几年来,教材.课程内容.教学方法.教学手段不断改 ...
随机推荐
- Sublime Theme
Package Control Messages======================== Theme - Spacegray----------------- Thanks for insta ...
- JsonFX 序列化反序列化
/// <summary> /// Json 序列化工具类 /// </summary> public class SerializeJsonUtility { /// < ...
- 利用问答机器人API开发制作聊天类App
缘起 很久没写项目了,所以单纯的想练练手,正好看到有问答机器人的接口,想到之前也做过聊天项目,为什么不实验一下呢.当然也是简单调用接口的项目,并没有真正的完成问答的算法等等.业余项目,功能不齐全,只实 ...
- 常见的开发语言(或IT技术)一览
Java. Android. iOS. Web前端. Python. .NET. PHP. C/C++. Linux 数据库技术
- spring-boot-redis-cluster简单整合例子
代码地址如下:http://www.demodashi.com/demo/13184.html 一.前言 spring-boot项目整合redis很常见,Redis 一般上生产的时候都是以集群模式部署 ...
- NodeJS on Nginx: 使用nginx反向代理处理静态页面
最近OurJS后台已经从纯node.js迁移到了Nginx+NodeJS上来了,感觉性能提升了不少,特与大家分享. Nginx ("engine x") 是一个高性能的 HTTP ...
- select/poll/epoll原理探究及总结
select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作.但select ...
- 单例模式获取JDBC连接
package com.jdbc.test; import java.io.IOException; import java.io.InputStream; import java.sql.Conne ...
- 使用scp免passwordserver间传递文件
1.aserver下执行命令 ssh-keygen -t rsa 2.三个回车 3.在用户的文件夹下 ~/.ssh/产生两个文件,id_rsa,id_rsa.pub 4.把aserver下相应的文件 ...
- Atitit.编程语言and 自然语言的比较and 编程语言未来的发展
Atitit.编程语言and 自然语言的比较and 编程语言未来的发展 1. 单词的间隔靠空格,编程的单词的间隔靠分界符..1 2. 语句分界符:自然语言使用逗号,编程语言使用分号1 3. 换行1 4 ...