codeforce vk cup2017
2 seconds
256 megabytes
standard input
standard output
Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=101 and y=011 differs exactly in two bits.
Vasya wants to know how many pairs of indexes (i, j) are in his sequence so that i < j and the pair of integers ai and aj is k-interesting. Your task is to help Vasya and determine this number.
The first line contains two integers n and k (2 ≤ n ≤ 105, 0 ≤ k ≤ 14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.
The second line contains the sequence a1, a2, ..., an (0 ≤ ai ≤ 104), which Vasya has.
Print the number of pairs (i, j) so that i < j and the pair of integers ai and aj is k-interesting.
4 1
0 3 2 1
4
6 0
200 100 100 100 200 200
6
In the first test there are 4 k-interesting pairs:
- (1, 3),
- (1, 4),
- (2, 3),
- (2, 4).
In the second test k = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:
- (1, 5),
- (1, 6),
- (2, 3),
- (2, 4),
- (3, 4),
- (5, 6).
用的新函数__builtin_popcount(i^j)计算i和j二进制不同的个数 用异或判断
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=,maxn=+,inf=0x3f3f3f3f; ll sum[maxn];
int main()
{
ll n,k,ans=;
memset(sum,,sizeof(sum));
scanf("%I64d%I64d",&n,&k);
for(int i=;i<n;i++)
{
ll a;
scanf("%I64d",&a);
sum[a]++;
}
if(!k)
{
for(int i=;i<=;i++)
ans+=(sum[i]*(sum[i]-)/);
}
else
{
for(int i=;i<=;i++)
for(int j=;j<i;j++)
if(__builtin_popcount(i^j)==k)
ans+=(sum[i]*sum[j]);
}
printf("%I64d\n",ans);
return ;
}
/*
4 1
0 3 2 1
4
*/
codeforce vk cup2017的更多相关文章
- VK CUP2017 ROUND 1
来自FallDream的博客.未经允许,请勿转载,谢谢. ---------------------------------------------------- 和ditoly组队打vkcup,原来 ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- cf.VK CUP 2015.B.Mean Requests
Mean Requests time limit per test 4 seconds memory limit per test 256 megabytes input standard input ...
- DP VK Cup 2012 Qualification Round D. Palindrome pairs
题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)爆零记
昨晚一个瓜皮说今晚有cf,听说是晚间场,我瞅了一眼,娃,VK Cup,上分的好机会,看着比赛时间就有点心酸了,0:35,当时一直在纠结要不要打的问题,当时想着应该不难吧,要不打一下吧,要不还是看看题先 ...
随机推荐
- 任何一款IDE的设计思路
我们以Windows操作系统为例.现在,基于操作系统的任何计算机语言,我们说都是高级语言,从C开始.无论是哪一种,都是通过操作系统的API与计算机交互.即便.Net的FrameWork库从一定意义上何 ...
- reactjs Uncaught TypeError: Cannot read property 'location' of undefined
reactjs Uncaught TypeError: Cannot read property 'location' of undefined reactjs 路由配置 怎么跳转 不成功 国内搜索引 ...
- IE6 margin 双倍边距解决方案
一.什么是双边距Bug? 先来看图: 我们要让绿色盒模型在蓝色盒模型之内向左浮动,并且距蓝色盒模型左侧100像素.这个例子很常见,比如在网页布局中,侧边栏靠左侧内容栏浮动,并且要留出内容栏的宽度.要实 ...
- 如何给sublime text3安装汉化包?so easy 哦
这是我本人亲身测试过的,肯定有效,没用的话怪我咯. 首先安装package control,然后安装汉化包即可,很简单哦!!! 1.安装package control:打开sublime,使用快捷键: ...
- css颜色代码对照
FFFFFF #DDDDDD #AAAAAA #888888 #666666 #444444 #000000 #FFB7DD #FF88C2 #FF44AA #FF0088 #C10066 #A ...
- 【Yii系列】处理请求
缘起 这一章是Yii系列的第三章,前两章给大伙讲解了Yii2.0的安装与Yii2.0的基本框架及基础概念,传送门: [Yii2.0的安装与调试]:http://www.cnblogs.com/rive ...
- 通用数据库帮助类DBHelper(含log日志信息实时记录)
项目需要,需要一个通用的数据库操作类,增删改查.事务.存储过程.日志记录都要有,于是在已有的帮助类上做了一些改进,并将log4j的.NET版--log4net嵌入其中记录sql的执行环境和状态. 用起 ...
- Omi架构与React Fiber
原文链接-https://github.com/AlloyTeam/omi/tree/master/tutorial 写在前面 Omi框架在架构设计的时候就决定把update的控制权交给了开发者,视灵 ...
- Mybatis 中一对多,多对一的配置
现在有很多电商平台,就拿这个来说吧.顾客跟订单的关系,一个顾客可以有多张订单,但是一个订单只能对应一个顾客. 一对多的顾客 <?xml version="1.0" encod ...
- Ubuntu上手动安装Kubernetes
背景 两台Ubuntu16.04服务器:ip分别为192.168.56.160和192.168.56.161.. Kubernetes版本:1.5.5 Docker版本:1.12.6 etcd版本:2 ...