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 ...
随机推荐
- -bash: ./start.sh: /bin/sh^M: bad interpreter: No such file or directory 错误解决方案
问题描述:sh文件中,在win环境下,用WinSCP编辑,出现如下错误: -bash: ./start.sh: /bin/sh^M: bad interpreter: No such file or ...
- 【Luogu】P1411树(树形高精DP)
题目链接 我貌似又做了一道高精题呢(笑) 这题的DP方程很好想,设f[i][j]表示i为根的子树,i所在联通块大小为j的最大值,然后乱搞 但是要高精,那么搞是得要高精除的 所以考虑f[i][j]是除以 ...
- mybatis学习(九)——动态sql
MyBatis 的强大特性之一便是它的动态 SQL.可以根据不同条件拼接 SQL 语句. 动态 SQL 元素和使用 JSTL 或其他类似基于 XML 的文本处理器相似.主要由以下几种元素. if wh ...
- debug模式总是自动跳到ThreadPoolExecutor
debug模式下eclipse总是自动跳到ThreadPoolExecutor解决方案 debug模式下eclipse总是自动跳到ThreadPoolExecutor解决方案 在eclipse中点击W ...
- java中文乱码问题解决
1 处理乱码方式: 1 连接数据库的时候 jdbc.properties:jdbc:mysql://localhost:3306/myproject?useUnicode=true&chara ...
- SPOJ QTREE4 - Query on a tree IV
You are given a tree (an acyclic undirected connected graph) with N nodes, and nodes numbered 1,2,3. ...
- 从Java源码到Java字节码
Java最主流的源码编译器,javac,基本上不对代码做优化,只会做少量由Java语言规范要求或推荐的优化:也不做任何混淆,包括名字混淆或控制流混淆这些都不做.这使得javac生成的代码能很好的维持与 ...
- Mac 下安装Ant
转自:http://blog.csdn.net/crazybigfish/article/details/18215439 如果你不知道什么是ant,请不要浪费你的时间继续读下去了.或者你对ant是什 ...
- 2016-2017 ACM-ICPC, South Pacific Regional Contest (SPPC 16)
题目链接 Codeforces_Gym_101177 Problem A Anticlockwise Motion 直接模拟即可 #include<iostream> #include ...
- 基于sklearn的分类器实战
已迁移到我新博客,阅读体验更佳基于sklearn的分类器实战 完整代码实现见github:click me 一.实验说明 1.1 任务描述 1.2 数据说明 一共有十个数据集,数据集中的数据属性有全部 ...