• 51Nod 1315 合法整数集


    一个整数集合S是合法的,指S的任意子集subS有Fun(SubS)!=X,其中X是一个固定整数,Fun(A)的定义如下:

    A为一个整数集合,设A中有n个元素,分别为a0,a1,a2,...,an-1,那么定义:Fun(A)=a0 or a1 or ... or an-1;Fun({}) = 0,即空集的函数值为0.其中,or为或操作。
    现在给你一个集合Y与整数X的值,问在集合Y至少删除多少个元素能使集合Y合法?
     
    例如:Y = {1,2,4},X=7;显然现在的Y不合法,因为 1 or 2 or 4 = 7,但是删除掉任何一个元素后Y将合法。所以,答案是1.
    Input
    第一行两个整数N,X,其中N为Y集合元素个数,X如题所述,且1<=N<=50,1<=X<=1,000,000,000.
    之后N行,每行一个整数yi,即集合Y中的第i个元素,且1<=yi<=1,000,000,000.
    Output
    一个整数,表示最少删除多少个元素。
    Input示例
    5 7
    1
    2
    4
    7
    8
    Output示例
    2
    注意是任意子集那么首先把所有可能得到x的元素找出来,最后求每个元素的贡献值
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/stck:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 0x3f3f3f3f
    #define mem(a) ((a,0,sizeof(a)))
    typedef long long ll;
    ll a[55],b[55],res[55],n,x,ans,y,cnt=100;
    int top=0;
    int main()
    {
        scanf("%lld%lld",&n,&x);
        ans=x;
        while(ans)
        {
            a[top++]=ans%2;
            ans/=2;
        }
        for(int i=0;i<n;i++)
        {
            scanf("%lld",&y);
            if((y|x)!=x) continue;
            int top=0;
            while(y)
            {
                if(y&1) b[top]++;
                y/=2;
                top++;
            }
        }
        for(int i=0;i<=50;i++)
            if(a[i]) cnt=min(cnt,b[i]);
        printf("%d
    ",cnt);
        return 0;
    }
  • 相关阅读:
    我的SICP习题解答-chapter 1
    redis主从复制实验,使用ruby
    python连接redis
    ruby连接redis
    python中的classmethod和staticmethod有什么不同[转载]
    安装配置rails环境
    试用memcached高可用repcached
    试用memcached
    Python一个很好玩的特性decorator
    mybatis随笔四之MapperProxy
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/8973985.html
Copyright © 2020-2023  润新知