Codeforces 467B Fedor and New Game(暴力)

248 篇文章 0 订阅

题目链接:Codeforces 467B Fedor and New Game

题目大意:给定n,m,k,n种士兵,m个部队,兵种不同数量小于等于k的为友军。然后给出m+1行,前m行表示需要判定的部队,第m+1行Fedor的部队。(按照二进制形式给定)

解题思路:直接取亦或,然后判断1的个数是否小于等于k。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1005;

int n, m, k, c[maxn];

inline int bitcount (int x) {
    return x == 0 ? 0 : bitcount(x>>1) + (x&1);
}

int main () {
    int ret = 0;
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i <= m; i++)
        scanf("%d", &c[i]);

    for (int i = 0; i < m; i++) {
        if (bitcount(c[i]^c[m]) <= k)
            ret++;
    }
    printf("%d\n", ret);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值