CSU - 2055 Wells‘s Lottery
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
#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的更多相关文章
- UVA10325 The Lottery(容斥原理)
题意: 给n,m,和m个数(k1~km).求1~n中有多少个数不是(k1~km)中任意一数的倍数. 题解: 容斥模板题.反面考虑,a的倍数有n/a个:既是a,也是b的倍数,即lcm(a,b)的倍数有n ...
- EX14 彩票中奖 (lottery.pas/c/cpp)
[题目描述]小明想试试运气去购买彩票,所以他开始研究彩票大乐透的玩法:超级大乐透是指由购买者从01—35共35个号码中选取5个号码为前区号码,并从01—12共12个号码中选取2个号码为后区号码组合为一 ...
- csu 1812: 三角形和矩形 凸包
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
- CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...
- CSU 1120 病毒(DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...
- CSU 1116 Kingdoms(枚举最小生成树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...
- CSU 1113 Updating a Dictionary(map容器应用)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...
- CSU 1333 Funny Car Racing (最短路)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...
- CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...
随机推荐
- 英雄无敌3开源引擎vcmi的编译安装
TAGS: Heroes3, vcmi, opensourceDATE: 2013-08-23 vcmi是什么? vcmi 是经典的 SLG 英雄无敌3 的开源游戏引擎.原来的英雄无敌3只能在Wind ...
- 【leetcode 简单】 第五十七题 删除链表中的节点
删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4 ...
- Sublime遇见中文乱码问题?
今天在写demo的时候,突然发现html页面上的中文在浏览器上显示乱码~!!!!! 这时,我根据网上的提示安装了两个插件:converttoUtf-8,support Gbk ~~~然而,好像无济于事 ...
- 《区块链100问》第82集:应用类项目Golem
Golem是第一个基于以太坊区块链打造的计算资源交易平台.通过区块链,Golem能链接全球的算力资源,从而实现计算能力的全球共享.应用所有者和个体用户(算力“请求方”)可以点对点地从其他用户处租用算力 ...
- 单调栈(G - Sliding Window POJ - 2823 )
题目链接:https://cn.vjudge.net/contest/276251#problem/G 题目大意:给你n和m,然后问你对于(m,n)这中间的每一个数,(i-m+1,i)这个区间的最小值 ...
- 【Nginx】 Nginx实现端口转发
什么是端口转发 当我们在服务器上搭建一个图书以及一个电影的应用,其中图书应用启动了 8001 端口,电影应用启动了 8002 端口.此时如果我们可以通过 localhost:8001 //图书 loc ...
- C#利用System.Net发送邮件
啥也不说了,直接上干货 using System.Net.Mail;using System.Net; //使用发送邮件的邮箱 var emailAcount = "826217795@qq ...
- p,br,hn,b,i,u,s,sup,sub标签
<!-- -->注释 <p></p>段落标签 <br />换行标签 <h1></h1> 字体标签 最大 <h6> ...
- pycharm tornado 项目 配置
ycharm 配置tornado项目 使得能够像django项目一样运行
- SQLAlchemy-对象关系教程ORM-query
一:对象关系教程查询 一个 Query创建对象时使用 Session的query()方法 .此函数接受一个变量数量的参数,可以是任何类和class-instrumented描述符的组合. Query返 ...