After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».

The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer xi. Consider binary representation of xi: if the j-th bit of number xi equal to one, then the army of the i-th player has soldiers of the j-th type.

Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.

Input

The first line contains three integers nmk (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000).

The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.

Output

Print a single integer — the number of Fedor's potential friends.

Sample test(s)
Input
7 3 1
8
5
111
17
Output
0
Input
3 3 3
1
2
3
4
Output
3

【分析】:
“<< ”   位左移,相当于乘以2
“>>" 位右移,相当于除以2
“&” 按为与,位数都为1时为1,否则为0
“^” 异或,不同为1,相同为0 新技能: a & ( << j ) 表示数a二进制的第j位是什么
【代码】:
#include <bits/stdc++.h>

using namespace std;
const int maxn = ;
int n,m,k,a[maxn]; int main()
{
int sum=,ans=;
cin>>n>>m>>k;
for(int i=;i<=m;i++)
cin>>a[i];
for(int i=;i<m;i++)
{
sum=; //注意内部清零
for(int j=;j<n;j++)
if( ( a[i]&(<<j) )^( a[m]&(<<j) ) ) sum++;
if(sum<=k) ans++;
} cout<<ans<<endl;
return ;
}

Codeforces Round #267 (Div. 2) B. Fedor and New Game【位运算/给你m+1个数让你判断所给数的二进制形式与第m+1个数不相同的位数是不是小于等于k,是的话就累计起来】的更多相关文章

  1. Codeforces Round #267 (Div. 2) B. Fedor and New Game

    After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...

  2. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  3. Codeforces Round #267 (Div. 2) D. Fedor and Essay tarjan缩点

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS

    题意:给一篇文章,再给一些单词替换关系a b,表示单词a可被b替换,可多次替换,问最后把这篇文章替换后(或不替换)能达到的最小的'r'的个数是多少,如果'r'的个数相等,那么尽量是文章最短. 解法:易 ...

  5. 01背包 Codeforces Round #267 (Div. 2) C. George and Job

    题目传送门 /* 题意:选择k个m长的区间,使得总和最大 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 01背包思想,状态转移方程:dp[i][j ...

  6. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  7. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  8. Codeforces Round #267 (Div. 2)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  9. Codeforces Round #267 (Div. 2) C. George and Job DP

                                                  C. George and Job   The new ITone 6 has been released ...

随机推荐

  1. 使用Subversion进行源代码管理(二):创建和发布版本库[转]

    原文出处: http://www.blogjava.net/youxia/archive/2007/10/23/155372.html 我的上一篇随笔讲了怎么使用Subversion客户端去连接服务器 ...

  2. 《Cracking the Coding Interview》——第17章:普通题——题目5

    2014-04-28 22:44 题目:猜数字游戏.四个数字,每个都是0~9之间.你每猜一次,我都告诉你,有多少个位置和数字都对(全对),有多少个位置错数字对(半对).比如“6309”,你猜“3701 ...

  3. Jmeter 参数化之 CSV Data Set Config 循环读取参数

    对于做接口和性能测试,个人感觉Jmeter是一个非常方便易学的工具,今天随笔记录Jmeter 参数化之 CSV Data Set Config. 首先在开始记录之前,先搞明白2个问题 1.什么是参数化 ...

  4. Python全栈工程师(每周总结:1)

    ParisGabriel   python今年9月份将被国家纳入计算机二级资格证 先学就是鼻祖 几年后你就是大牛      Python人工智能从入门到精通         week summer: ...

  5. ZOJ 3717 Balloon ( TLE )

    正解2-SAT. 我用DLX想搜一搜的,结果TLE了…… 没什么遗憾,最起码我尝试过了. 扔个代码留作纪念. #include <cstdio> #include <cstring& ...

  6. android自定义控件属性

    有两种方法为自定义的控件设置属性 . 来自为知笔记(Wiz)

  7. Mysql入门的10条语句

    1.查看当前服务器下面,有那些库(database)? 答: show databases; 2.如何创建一个数据库? 答 : create database 最后面在写数据库名:分号结束 3.选择数 ...

  8. 写把proto函数搞清楚

    在做blk层之前,先把proto搞清楚 ffi_lua metatype可以给函数加方法, lua中冒号是啥意思?冒号会传入self,但是点号不会传入self

  9. kafka-0.9消费者新API

    ## kafka-0.9消费者新API 注:以下仅限kafka版本0.9以上Consumer新版api Consumer自动提交示例: Properties props = new Propertie ...

  10. Redis Sorted Set

    Redis Sorted Set Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过分数来为集合 ...