2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys
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 and B 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.
Input
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
Output the number of pairs that are allowed.
Example
2 5
2 1 3
5 3 1 5 4 2
0.66489
0
3 1
1 1
1 1
1 1
0.85809
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e5 + ;
int main()
{
int t,k=,n,x,a[M],m,p[];
ll b[M];
double dd;
scanf("%d%d",&t,&m);
for(int i=;i<=m+;i++){
p[i] = pow(,i-);
}
memset(b,,sizeof(b));
while(t--){
scanf("%d",&n);
memset(a,,sizeof(a));
for(int i = ;i < n;i++){
scanf("%d",&x);
a[x] = ;
}
int ans = ;
for(int i=;i<=m;i++){
ans += (p[i]*a[i]);
}
//cout<<ans<<endl;
b[ans]++;
} //设一个十进制的数,b数组是因为总共不超过1024,然后他有1e5的集合,有重复;
cin>>dd;
int c[];
for(int k=;k<=m;k++)
c[k]=pow(,k-);
ll sum = ;
for(int i = ;i <= p[m+]; i++){
for(int j = i;j <= p[m+]; j++){
int num1 = (i|j),num2=(i&j);
double cnt1=,cnt2=;
for(int k=;k<=m;k++)
{
if(num1&c[k])
cnt1++;
if(num2&c[k])
cnt2++;
}
//cout<<cnt1/cnt2<<endl;
if(cnt2/cnt1>=dd&&i!=j&&b[i])
sum+=b[i]*b[j];
else if(cnt1/cnt2>=dd&&i==j&&b[i]){
sum+=b[i]*(b[i]-)/;
}
}
}
cout<<sum<<endl;
}
2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys的更多相关文章
- GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树
G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...
- 【Codeforces Round #424 (Div. 2) D】Office Keys
[Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都 ...
- Codeforces663E Binary Table(FWT)
题目 Source http://codeforces.com/contest/663/problem/E Description You are given a table consisting o ...
- [gym100956]Problem J. Sort It! BIT+组合数
source : Pertozavodsk Winter Training Camp 2016 Day 1: SPb SU and SPb AU Contest, Friday, January 29 ...
- C - Haiku
Problem description Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syl ...
- 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. ...
- 【Codeforces Round 725】Canada Cup 2016
模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) E
链接:http://codeforces.com/gym/101116 学弟写的,以后再补 #include <iostream> #include <algorithm> # ...
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) J
链接:http://codeforces.com/gym/101116 题意:给出n个点,要求一个矩形框将(n/2)+1个点框住,要面积最小 解法:先根据x轴选出i->j之间的点,中间的点(包括 ...
随机推荐
- IOS学习5——属性与成员变量
[转]iOS中属性与成员变量的区别 ios中属性修饰符的作用 1. 属性用property声明 2. 简而言之,对于目前的ios开发,属性和成员变量的区别,完全可以不管. 3. 这个是历史原因造成的. ...
- AutoLayout的几种方法
1.XIB 2.Fram 3.屏幕比例适配(个人比较推荐) iOS屏幕适配(尺寸适配) 4.NSLayoutConstraint. 5.Masonry 概述 使用 Objective-C 纯代码编 ...
- bzoj 4012: [HNOI2015]开店 主席树
Description 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到 人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱.这样的 想法当然非常好啦,但是她们也发现 ...
- jmeter远程分布执行遇到的网卡坑(A Test is currently running,stop or ....)
周末加班做一个项目app的性能测试,单机负载时由于公司给每个人的网络带宽上传下载流量就1M,300个用户并发就已经网络IO饱和了,虽然和相关部门协调过资源问题,但是收效甚微,因此打算先用分布部署压力机 ...
- UNIX域协议(命名套接字)
这里主要介绍命名UNIX域套接字 1.什么是UNIX域套接字Unix域协议并不是一个实际的协议族,而是在单个主机上执行客户/服务通信的一种方式.是进程间通信(IPC)的一种方式.它提供了两类套接字:字 ...
- Automata
A deterministic finite automaton is represented formally by a 5-tuple (Q,Σ,δ,q0,F), where: Q is a fi ...
- Python图片爬虫
1.今天给大家介绍自己写的一个图片爬虫,说白了就是从网页自动上下载需要的图片 2.首先选取目标为:http://www.zhangzishi.cc/涨姿势这个网站如下图,我们的目标就是爬取该网站福利社 ...
- egrep及扩展正则表达式 与正则表达式不同处
egrep及扩展正则表达式与正则表达式不同处 正则表达式有两类,分为基本正则表达式和扩展正则表达式,是使用命令egrep来使用扩展正则表达式,它与grep很多功能相同,仅在元字符上实现了些扩展扩展,在 ...
- Struts2思维导图
自己感觉自己的知识不是很扎实,所以昨天留时间复习知识,昨天边复习边画了一个思维导图.不知道自己画的对不对,还没有画完.有错的地方大家请和我说.希望自己能更加牢固的记住这些知识. 不说废话,开图.图有点 ...
- TabHost用法
tabhost用两种方法 方法一:Activity继承TabActivity后用getTabHost()方法来获取tabhost(前提:Activity的setContentView要删除,这样布局才 ...