现在的位置: 首页 > 综合 > 正文

Codeforces 467B Fedor and New Game(暴力)

2019年08月20日 ⁄ 综合 ⁄ 共 474字 ⁄ 字号 评论关闭

题目链接: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;
}

抱歉!评论已关闭.