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 n,
m, k
(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
题意:给你m+1个数让你推断所给的数的二进制形式与第m+1个数不想同的位数是否小于等于k。累计答案
思路:题意题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1010; int num[maxn], cnt; int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < m; i++)
scanf("%d", &num[i]);
scanf("%d", &cnt);
int ans = 0;
for (int i = 0; i < m; i++) {
int cur = 0;
for (int j = 0; j < n; j++)
if (((1<<j)&num[i]) != ((1<<j)&cnt))
cur++;
if (cur <= k)
ans++;
}
printf("%d\n", ans);
return 0;
}

Codeforces Round #267 (Div. 2) B. Fedor and New Game的更多相关文章

  1. 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 ...

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

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

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

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

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)

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

  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. Spring c3p0连接池通过Hibernate配置

    首先进行Hibernate配置,详见http://www.cnblogs.com/claricre/p/6509931.html 然后调用这三个包. 配置hibernate.cfg.xml文件: &l ...

  2. hibernate框架的搭建与简单实现增删改

    Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQL语句,自 ...

  3. iOS学习笔记27-摄像头

    一.摄像头 在iOS中,手机摄像头的使用有以下两种方法: UIImagePickerController拍照和视频录制 优点:使用方便,功能强大 缺点:高度封装性,无法实现一些自定义工作 AVFoun ...

  4. hihoCoder #1047 Random Tree

    题意 给出点数为 $n$($n \le 1000$)的完全图 $K_n$,带边权.随机出 $K_n$ 的一棵生成树 $T$.求 $T$ 上任意两点间距离的期望. 解法 固定两点 $u$.$v$($u ...

  5. Java防止SQL注入的途径介绍

    为了防止SQL注入,最简洁的办法是杜绝SQL拼接,SQL注入攻击能得逞是因为在原有SQL语句中加入了新的逻辑,如果使用PreparedStatement来代替Statement来执行SQL语句,其后只 ...

  6. python time模块 sys模块 collections模块 random模块 os模块 序列化 datetime模块

    一 collections模块 collections模块在内置的数据类型,比如:int.str.list.dict等基础之上额外提供了几种数据类型. 参考博客 http://www.pythoner ...

  7. Mysql常用语句记录

    建表语句,带自增字段 create table test ( id int auto_increment primary key, name ) not null, password ) not nu ...

  8. 远征(expedition)

    [题目描述] 寒枫将军将要带领他的部队去圣雪山消灭那里的冰龙. 部队分成了若干个小队,属于同一个小队的人兵种相同.寒枫将军有着杰出的指挥能力,在战斗的时候,寒枫将军能够让所有相同兵种的人互相配合,使t ...

  9. angular杂谈

    <element ng-include="filename" onload="expression" autoscroll="expressio ...

  10. postgresql-9.0.18-1-linux.run启动

    下载地址:http://www.enterprisedb.com/products-services-training/pgdownload选择合适版本 基本都是下一步就可以到设置密码时记住密码以后要 ...