codeforces Fedor and New Game

#include<iostream>
#include<stack>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;

int a[1005];

int main(){
    int n, m, k;
    int ans, ret=0;
    scanf("%d%d%d", &n, &m, &k);
    for(int i=1; i<=m; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &ans);
    for(int i=1; i<=m; ++i){
        int tmp = ans^a[i], cnt=0;
        while(tmp){
            if(tmp&1) ++cnt;
            tmp>>=1;
        }
        if(cnt<=k)  ++ret;
    }
    printf("%d\n", ret);
    return 0;
}
时间: 2024-11-03 10:19:20

codeforces Fedor and New Game的相关文章

Codeforces 467D Fedor and Essay(bfs)

题目链接:Codeforces 467D Fedor and Essay 题目大意:给定一个含n个单词的文本,然后给定m种变换,要求变换后r的个数尽量少,长度尽量短,不区分大小写. 解题思路:bfs,将每个单词处理成长度以及r的个数,然后从最优的开始更新即可,类似dp. #include <cstdio> #include <cstring> #include <map> #include <string> #include <vector> #

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 for

Codeforces 1179 D - Fedor Runs for President

D - Fedor Runs for President 思路: 推出斜率优化公式后,会发现最优点只可能来自凸斜率中的第一个元素和最后一个元素, 这两个元素不用维护凸斜率也能知道,就是第一个和上一个元素 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi

CodeForces 754D Fedor and coupons ——(k段线段最大交集)

还记得lyf说过k=2的方法,但是推广到k是其他的话有点麻烦.现在这里采取另外一种方法. 先将所有线段按照L进行排序,然后优先队列保存R的值,然后每次用最小的R值,和当前的L来维护答案即可.同时,如果Q的size()比k大,那么就弹出最小的R. 具体见代码: 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <set> 5 #include <vec

CodeForces 754D Fedor and coupons (优先队列)

题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, 之间的距离.优先队列只要存储右端点就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <

Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS

题意:给一篇文章,再给一些单词替换关系a b,表示单词a可被b替换,可多次替换,问最后把这篇文章替换后(或不替换)能达到的最小的'r'的个数是多少,如果'r'的个数相等,那么尽量是文章最短. 解法:易知单词间有二元关系,我们将每个二元关系建有向边,然后得出一张图,图中可能有强连通分量(环等),所以找出所有的强连通分量缩点,那个点的minR,Len赋为强连通分量中最小的minR,Len,然后重新建图,跑一个dfs即可得出每个强连通分量的minR,Len,最后O(n)扫一遍替换单词,统计即可. 代码

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th