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
  1. 7 3 1
  2. 8
  3. 5
  4. 111
  5. 17
Output
  1. 0
Input
  1. 3 3 3
  2. 1
  3. 2
  4. 3
  5. 4
Output
  1. 3
  2. 题意:给你m+1个数让你推断所给的数的二进制形式与第m+1个数不想同的位数是否小于等于k。累计答案
  3. 思路:题意题
  4. #include <iostream>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <algorithm>
  8. using namespace std;
  9. const int maxn = 1010;
  10. int num[maxn], cnt;
  11. int main() {
  12. 	int n, m, k;
  13. 	scanf("%d%d%d", &n, &m, &k);
  14. 	for (int i = 0; i < m; i++)
  15. 		scanf("%d", &num[i]);
  16. 	scanf("%d", &cnt);
  17. 	int ans = 0;
  18. 	for (int i = 0; i < m; i++) {
  19. 		int cur = 0;
  20. 		for (int j = 0; j < n; j++)
  21. 			if (((1<<j)&num[i]) != ((1<<j)&cnt))
  22. 				cur++;
  23. 		if (cur <= k)
  24. 			ans++;
  25. 	}
  26. 	printf("%d\n", ans);
  27. 	return 0;
  28. }

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. 天气预报接口:SmartWeather API中key的计算方法

    这个代码大家都蛮感兴趣,我在git开源了一个用于收集天气信息的系统,基于python语言的,请大家参考: https://github.com/BerlinSun/WeatherForecast -- ...

  2. 【Luogu】P3356火星探险问题(费用流)

    题目链接 网络流一条边都不能多连?没道理呀? 不过单看这题的确是个sb题…… #include<cstdio> #include<algorithm> #include< ...

  3. bzoj 3544 [ONTAK2010]Creative Accounting 贪心

    Description 给定一个长度为N的数组a和M,求一个区间[l,r],使得(\sum_{i=l}^{r}{a_i}) mod M的值最大,求出这个值,注意这里的mod是数学上的mod Input ...

  4. mac上安装chromedriver

    默认下载2.35版本,放置到/usr/local/bin #!/usr/bin/env bash # ------------------------------------------------- ...

  5. idea部署项目到远程tomcat

    之前做项目,一直都是把本地的源码上传到svn,服务器是通过ant或者maven脚本来编译的生成项目的.每次都要单独登录接服务器进行项目的部署和发布,感觉特别繁琐.(特别是在有几套服务器的情况下,简直就 ...

  6. 相关分析 BZOJ 4821

    相关分析 [问题描述] Frank对天文学非常感兴趣,他经常用望远镜看星星,同时记录下它们的信息,比如亮度.颜色等等,进而估算出星星的距离,半径等等.Frank不仅喜欢观测,还喜欢分析观测到的数据.他 ...

  7. 视音频数据处理入门:RGB、YUV像素数据处理【转】

    转自:http://blog.csdn.net/leixiaohua1020/article/details/50534150 ==================================== ...

  8. Git基础篇【转】

    转自:https://i.cnblogs.com/EditPosts.aspx?opt=1 1.设置名字与邮箱 $ Git config –global user.name “YourName” $ ...

  9. svg格式矢量图引入方法

    引入方法: span { background: url('1.svg') no-repeat; background-size: 20px 20px; background-position: 0 ...

  10. AC日记——最短路 洛谷 P2384

    题目背景 狗哥做烂了最短路,突然机智的考了Bosh一道,没想到把Bosh考住了...你能帮Bosh解决吗? 他会给你100000000000000000000000000000000000%10金币w ...