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之间的点,中间的点(包括 ...
随机推荐
- Python Xcode搭建Python环境以及使用PyCharm CE
pycharm CE下载 使用教程 1.基础学习网站 2.在Xcode7中搭建python开发环境,这个不行了就试试第二个,我是第二个可以正常输出了,第一个没有输出 3.Python学习-MAC下 ...
- Ionic2 cordova angular2 打包到Android apk环境搭建
一.前言 前段时间,公司有个APP项目需要支持不同平台,于是采用了Ionic2 + cordova + angular2,在搭建环境过程中遇到了不少问题,刚好最近有时间整理出来. 二.开发环境搭建 参 ...
- Microsoft Visual Studio 2012旗舰版(VS2012中文版下载)官方中文版
Microsoft Visual Studio 2012 Ultimate旗舰版(VS2012中文版下载)是一个最先进的开发解决方案,它使各种规模的团队能够设计和创建出使用户欣喜的引人注目的应用程序. ...
- Wincc flexable的IO域组态
1.题目 2.新建三个变量 3.组态画面,添加IO域1 1)常规设置 2)属性设置 4.组态IO域2 1)常规项 2)属性设置 5.组态第三个IO域 1)常规设置 2)属性设置 6.此外可以设置动画 ...
- RabbitMQ教程(一) ——win7下安装RabbitMQ
RabbitMQ依赖erlang,所以先安装erlang,然后再安装RabbitMQ; 下载RabbitMQ,下载地址: rabbitmq-server-3.5.6.exe和erlang,下载地址:o ...
- Elastic 技术栈之 Filebeat
Elastic 技术栈之 Filebeat 简介 Beats 是安装在服务器上的数据中转代理. Beats 可以将数据直接传输到 Elasticsearch 或传输到 Logstash . Beats ...
- Node.js 蚕食计划(三)—— Express 启航
如果看过上一篇<Node.js 蚕食计划>,就会发现手动搭建一个 web 服务器还是比较繁琐 而 express 就是一个可以极大地提高开发效率的 web 开发框架 一.创建项目 在 ex ...
- 转:java.lang.OutOfMemoryError: Java heap space错误及处理办法(收集整理、转)
以下是从网上找到的关于堆空间溢出的错误解决办法: Java.lang.OutOfMemoryError: Java heap space =============================== ...
- java基础只关键字final
final关键字简述 final关键字是在编写java程序中出现频率和很高的关键字,如果想要更好的编写java程序,那么掌握final关键字的运用是非常必要的.让我们先看一下final关键字可以修饰的 ...
- PHP 微信公众号-创建菜单-配置
1.服务号 2.基本配置 注意: URL: 确保能访问到你对应的文件 Token:随意设置,但是要与文件里的一致 3.网页授权 注意:填写网站域名 4.更具实际需求创建菜单