Description

As is known to all, Wells is impoverished.
When God heard that, God decide to help the poor Wells from terrible condition.
One day Wells met God in dream, God gave Wells a secret number which will bought Wells a great fortune and gifted Wells an ablility of transforming two lottery tickets x, y into a lottery ticket z (meet the condition that z==x or y).

Wells realized that the number must be the result of lottery, which would be worth ¥5,000,000! Wells was very excited, and can't help sharing this thought. The secret number is X, and Wells has purchase N lottery tickets a1,a2,a3....aNa1,a2,a3....aN but has not received them yet. And if lucky enough, Wells could pick some numbers of them satisfy that b1orb2orb3....orbk=Xb1orb2orb3....orbk=X, k is the amount of picked numbers.

How ever the owner of the lottery shop called SDJ, who decided to modify the lottery tickets and made Wells lost his fortune. In order to save energy to modify the lottery tickets, SDJ want to know the minimum amount of modification of lottery tickets.

Input

The input only contains one line.
First line contains two positive integers N (N<=105)(N<=105),X (X<=109)(X<=109) ,N means as described above Second line contains N number a1,a2...aN(0<=ai<=109),aia1,a2...aN(0<=ai<=109),ai means the number on i-th lottery tickets.

Output

Output a line only contains minimum amount of modification of lottery tickets.

Sample Input

3 7
4 2 1

Sample Output

1

Hint

It will be accepted after modifying any number.
The "or" in this problem means the bitwise or , for exmple , 0 or 0 = 0 ,0 or 1 = 1 , 1 or 1 = 1 , 3 or 5 =7.

Source

Author

Wells

题意:问最少改变多少个数,使任意数之间或运算都不能得到要求的数。
思路:考虑数字的每一个bit位,对于ai | X ==X 的说明对答案有贡献,把ai所有不为0的bit位的贡献+1即可 最后输出X所有为1的bit位的贡献得最小值 每个ai在判断有贡献后将1-30个bit位都for一遍计算贡献.

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
using namespace std;
int n, x,m;
int cnt[35];
int main()
{
while (~scanf("%d%d", &n, &x))
{
memset(cnt, 0, sizeof(cnt));
int min = (1 << 30); for (int i = 0; i < n; i++)
{
scanf("%d", &m);
if ((m | x) == x)
{
for (int j = 0; (1 << j) <= m; j++)
{
if ((1 << j)&m)
cnt[j]++;
}
}
}
for (int i = 0; (1<<i) <=x; i++)
{
if (((1 << i)&x))
min = min > cnt[i] ? cnt[i] : min;
}
printf("%d\n", min); } return 0;
}

CSU - 2055 Wells‘s Lottery的更多相关文章

  1. UVA10325 The Lottery(容斥原理)

    题意: 给n,m,和m个数(k1~km).求1~n中有多少个数不是(k1~km)中任意一数的倍数. 题解: 容斥模板题.反面考虑,a的倍数有n/a个:既是a,也是b的倍数,即lcm(a,b)的倍数有n ...

  2. EX14 彩票中奖 (lottery.pas/c/cpp)

    [题目描述]小明想试试运气去购买彩票,所以他开始研究彩票大乐透的玩法:超级大乐透是指由购买者从01—35共35个号码中选取5个号码为前区号码,并从01—12共12个号码中选取2个号码为后区号码组合为一 ...

  3. csu 1812: 三角形和矩形 凸包

    传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...

  4. CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...

  5. CSU 1120 病毒(DP)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...

  6. CSU 1116 Kingdoms(枚举最小生成树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...

  7. CSU 1113 Updating a Dictionary(map容器应用)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...

  8. CSU 1333 Funny Car Racing (最短路)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...

  9. CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...

随机推荐

  1. 《设计模式》-原则三:依赖倒置原则(DIP)

    这几天晚上回来都去玩了!没有坚持学习.真的好惭愧! 非常自责 后面一定要坚持 一气呵成  争取每天学一点,把这个学完. 今天主要是看了一下  设计模式中的 原则三: 依赖倒置原则(DIP) 官方是这样 ...

  2. [转载]WCF和ASP.NET Web API在应用上的选择

    http://www.cnblogs.com/shanyou/archive/2012/09/26/2704814.html http://msdn.microsoft.com/en-us/libra ...

  3. python核心编程笔记——Chapter5

    好吧,开始第五章习题: 5-2.又是老调重谈,raw_input这个函数真是非常麻烦,返回是str类型,没办法,只能在函数里面使用int内建.(就只是一道简单的两数相乘,哭了) #!/usr/bin/ ...

  4. soj1762.排座椅

    1762. 排座椅 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description 上课的时候总有一些同学和前后左右的人交头接耳,这是令 ...

  5. django的缓存,信号,序列化

    一 Django的缓存机制 1.1 缓存介绍 1.缓存的简介 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的 ...

  6. Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again错误解决

    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm  安装了epel源 但  yum -y ...

  7. [Openwrt扩展中篇]添加Aria2和webui

    上一篇说了我构建了简单的网络硬盘,这一篇说的是我构造的aria2和webui,大概是这样我觉得有了网络硬盘,那么我是不是可以远程下载呢,翻阅了网上资料发现迅雷的Xware貌似不更新了,然后我发现了ar ...

  8. python作业ATM(第五周)

    作业需求: 额度 15000或自定义. 实现购物商城,买东西加入 购物车,调用信用卡接口结账. 可以提现,手续费5%. 支持多账户登录. 支持账户间转账. 记录每月日常消费流水. 提供还款接口. AT ...

  9. 解决多个python的兼容问题

    方法1:将(安装路径和scripts)路径添加到系统环境变量,谁的顺序在前面谁就是默认的 方法2:修改python的名字,然后再终端输入比如python2或者python3

  10. FPGA设计方法检查表

    -----------------------摘自<FPGA软件测试与评价技术> 中国电子信息产业发展研究院 | 编著------------------------------- 文本格 ...