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 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.
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.
Print a single integer — the number of Fedor's potential friends.
7 3 1
8
5
111
17
0
3 3 3
1
2
3
4
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS
题意:给一篇文章,再给一些单词替换关系a b,表示单词a可被b替换,可多次替换,问最后把这篇文章替换后(或不替换)能达到的最小的'r'的个数是多少,如果'r'的个数相等,那么尽量是文章最短. 解法:易 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- Codeforces Round #267 (Div. 2)
A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- Codeforces Round #267 (Div. 2) C. George and Job DP
C. George and Job The new ITone 6 has been released ...
随机推荐
- BZOJ3325 [Scoi2013]密码 【manacher】
题目 Fish是一条生活在海里的鱼.有一天他很无聊,就到处去寻宝.他找到了位于海底深处的宫殿,但是一扇带有密码锁的大门却阻止了他的前进.通过翻阅古籍,Fish 得知了这个密码的相关信息: 该密码的长度 ...
- animation总结
1. animation结束后停在最后一帧 animation-fill-mode : forwards | both; /* 或者 */ animation: anim1 1s linear for ...
- maven项目中配置mvn源
在pom.xml中配置 <repositories> <!--for others--> <repository> <id>alimaven</i ...
- MAMP 10.10下启动报错解决方案
cd /Applications/MAMP/Library/binmv envvars _envvars
- Windows下载 Curl 命令
Windows下载 Curl 命令 描述: 不仅Linux命令行可以使用curl命令下载软件, Windows系统的cmd命令窗口也可以使用curl命令下载,并且更稳定. 原文作者:Wayne Zhu ...
- Yii CActiveForm 客户端验证(enableClientValidation)和自定义验证
使用Yii的CActiveForm默认使用服务器端模型(model)的rules规则验证数据. 但这会导致无谓的请求提交,比较好的方式是为了用户体验在客户端也验证,而为了安全性,在服务器端和数据库也做 ...
- Python初见
参考资料:http://wenku.baidu.com/link?url=_akpT-G5Tvf7ECyszSipOAhHXzjlpYu-RWPcRTYp_tecPOollPGUxXG4MH69MLN ...
- Centos7源码安装MySQL5.7
a.连接数据库报111 从一台linux远程连接另一台linux上的MySQL,出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx. ...
- Linux 设备驱动开发 —— platform设备驱动应用实例解析
前面我们已经学习了platform设备的理论知识Linux 设备驱动开发 —— platform 设备驱动 ,下面将通过一个实例来深入我们的学习. 一.platform 驱动的工作过程 platfor ...
- 第七讲_图像描述(图说)Image Captioning
第七讲_图像描述(图说)Image Captioning 本章结构 递归神经网络 时序后向传播(BPTT) 朴素Vanilla-RNN 基本模型 用sigmoid存在严重的梯度消失 LSTM长短时记忆 ...