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. windows下用python转换markdown到html

    方法一: 安装markdown, pip install markdown, 安装好后,python -m markdown xxx.md -f xxx.html 方法二:安装markdown2, p ...

  2. angular4 get,post请求(带参数,与不带参数)

    一:在app.module.ts引入HttpMoudle import { BrowserModule } from '@angular/platform-browser'; import { Htt ...

  3. 微服务深入浅出(6)-- 熔断器Hystrix

    概念 在分布式系统中,一种不可避免的情况就是某些服务会出现故障,导致依赖他们的其他服务出现远程调度的线程问题(雪崩效应).而Hystrix提供的熔断器,通过隔离服务的访问点,能阻止这种分布式系统中出现 ...

  4. UNIX环境高级编程 第5章 标准I/O库

    本章是关于C语言标准I/O库的,之所以在UNIX类系统的编程中会介绍C语言标准库,主要是因为UNIX和C之间具有密不可分的关系.由于UNIX系统存在很多实现,而每个实现都有自己的标准I/O库,为了统一 ...

  5. solr4.10.3部署到tomcat——(十)

    0. 准备环境:

  6. 【bzoj题解】1008 越狱

    题目描述 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱. 输入 输入两个整 ...

  7. accept系统调用

    /* * For accept, we attempt to create a new socket, set up the link * with the client, wake up the c ...

  8. shell脚本编程之“最简单的死循环”【转】

    转自:http://blog.chinaunix.net/uid-23046336-id-3475462.html 在linux下编程的程序猿都知道shell脚本,就算你不怎么熟悉,也应该听过的吧!那 ...

  9. VBA笔记-参考教程

    参考教程1: http://www.cnblogs.com/wuzhiblog/tag/VBA/ 1. VBA中字符换行 VBA中字符换行显示需要使用换行符来完成.下面是常用的换行符          ...

  10. java基础44 IO流技术(输出字节流/缓冲输出字节流)和异常处理

    一.输出字节流 输出字节流的体系: -------| OutputStream:所有输出字节流的基类(抽象类) ----------| FileOutputStream:向文件输出数据的输出字节流(把 ...