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 ...
随机推荐
- volatile的用法
在再有人问你Java内存模型是什么,就把这篇文章发给他中我们曾经介绍过,Java语言为了解决并发编程中存在的原子性.可见性和有序性问题,提供了一系列和并发处理相关的关键字,比如synchronized ...
- 洛谷P3327 [SDOI2015]约数个数和 【莫比乌斯反演】
题目 设d(x)为x的约数个数,给定N.M,求\(\sum_{i = 1}^{N} \sum_{j = 1}^{M} d(ij)\) 输入格式 输入文件包含多组测试数据.第一行,一个整数T,表示测试数 ...
- nvm、node、npm安装以及pycharm配置eslint
nvm.node.npm之间的区别 1. nvm的官方叫法:nodejs版本管理工具. nvm相当于是家长,一个家长可以管理多个孩子. 也就是说:一个nvm可以管理很多node版本和npm版本. 2. ...
- 使用electron将单页面vue webapp 打包成 PC端应用
在看张鑫旭博客得时候看到了electron这个东西,来了兴趣,就按照上面写的将已经做好得vue项目拿来试了试,出乎意料得顺利 electron简单说下electron,就是把 chrome内核和你的项 ...
- POJ3625 Building Roads
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10803 Accepted: 3062 Description Fa ...
- net9:图片文件转换成二进制流存入SQL数据库,以及从数据库中读取二进制流输出文件
原文发布时间为:2008-08-10 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- php validator classes
<?php /** * 验证类 */ class Validator { /* 函数名称:isNumber 简要描述:检查输入的是否为数字 输入:string 输出:boolean */ pub ...
- windows下webrtc的编译 2016(转)
====================20160124更新============================= 推荐一个FQ工具,shadowsocks,是需要付费的,一年也才不到100块,移 ...
- [原创][FPGA]Quartus实用小技巧(长期更新)
0. 简介 在使用Quartus软件时,经常会时不时的发现一些小技巧,本文的目的是总结所查阅或者发现到的小技巧,本文长期更新. 1. Quartus中的模板功能 最近在Quartus II的菜单里找到 ...
- Database | SQL
Basic of MySQL 创建数据库: mysql> create database xxj; Query OK, row affected (0.00 sec) 列举数据库: mysql& ...