[Codeforces 1013B] And
[题目链接]
http://codeforces.com/problemset/problem/1013/B
[算法]
不难发现,答案只有0,1,2,-1,共4种取值
分类讨论即可,计算时可以使用STL-map
[代码]
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010 int i,n,x;
int a[MAXN];
map<int,int> mp; int main()
{ scanf("%d%d",&n,&x);
for (i = ; i <= n; i++)
{
scanf("%d",&a[i]);
mp[a[i]]++;
}
for (i = ; i <= n; i++)
{
if (mp[a[i]] >= )
{
printf("0\n");
return ;
}
}
for (i = ; i <= n; i++)
{
if ((a[i] & x) == a[i]) continue;
if (mp[a[i] & x] >= )
{
printf("1\n");
return ;
}
}
mp.clear();
for (i = ; i <= n; i++) a[i] &= x;
for (i = ; i <= n; i++) mp[a[i]]++;
for (i = ; i <= n; i++)
{
if (mp[a[i]] >= )
{
printf("2\n");
return ;
}
}
printf("-1\n"); return ; }
[Codeforces 1013B] And的更多相关文章
- CodeForces - 1013B And 与运算暴力
题目链接: https://vjudge.net/problem/1735275/origin 基本思路: 本题思路比较简单,首先,我们知道 a & x = b, b & x = b; ...
- codeforces 1013B 【思维+并查集建边】
题目链接:戳这里 转自:参考博客 题意:给一个n*m的矩阵,放入q个点,这q个点之间的关系是,若已知这样三个点(x1,y1),(x2,y1),(x1,y2),可以在(x2,y2)处生成一个新的点,对于 ...
- Codeforces Round #500 (Div. 2) BC
CodeForces 1013B And CodeForces 1013C Photo of The Sky B 可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况 #inclu ...
- Codeforces Round 500 (Div 2) Solution
从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- 依存分析 Dependency Parsing
依存分析 Dependency Parsing 句子成分依存分析主要分为两种:句法级别的和语义级别的 依存句法分析 syntactic dependency parsing 语义依存分词 semant ...
- windows编译MaskRCNN
1.代码修改为3.0语言版本 2.setup_windows.py 文件内容为 #!/usr/bin/env python import numpy as np import os # on Wind ...
- Lazarus Reading XML- with TXMLDocument and TXPathVariable
也就是使用XPath的方式,具体语法规则查看http://www.w3school.com.cn/xpath/xpath_syntax.asp,说明得相当详细.这里列举例子是说明在Lazarus/FP ...
- HDU_1394_Minimum Inversion Number_线段树求逆序数
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- centos 7 配置nginx
安装nginx: curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0. ...
- CAD从二制流数据中加载图形(com接口VB语言)
主要用到函数说明: _DMxDrawX::ReadBinStream 从二制流数据中加载图形,详细说明如下: 参数 说明 VARIANT varBinArray 二制流数据,是个byte数组 BSTR ...
- Java报表统计导出Word-xdocin方式
官网:http://www.xdocin.com Controller层: //创建对象 XDocService xdocService = new XDocService(); //封装参数 Map ...
- Django CBV视图解决csrf认证
urls.py from django.conf.urls import url from appxx import views urlpatterns = [ url(r"^$" ...
- javascript 闭包笔记
先来解释一下闭包: 1.闭包就是函数嵌套函数 2.内部函数可以引用外部函数的参数和变量 3.参数和变量不会被垃圾回收机制所收回( 垃圾回收机制就是用完变量之后就在内存中释放 ) 使用闭包的好处: ...
- 火星人 2004年NOIP全国联赛普及组
题目描述 Description 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法.这种交流方法是这样的,首先,火星人把一个 ...