[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的概 ...
随机推荐
- Showplan 逻辑运算符和物理运算符参考
本文档已存档,并且将不进行维护. 运算符说明了 SQL Server 如何执行查询或数据操作语言 (DML) 语句. 查询优化器使用运算符生成查询计划,以创建在查询中指定的结果或执行在 DML 语句中 ...
- json和pickle的序列化
PICKle模块:
- POJ 2823 Sliding Window & Luogu P1886 滑动窗口
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 66613 Accepted: 18914 ...
- postgresql数据库部署
运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 一.postgresql数据库部署 1.前往postgresql安装包的目录(这里我部署的是10.5的版本) [root@web1 ...
- Django - Form和ModelForm
[TOC] 一. form介绍 1.生成页面可用的HTML标签 2. 提供input可以提交数据 3. 对用户提交的数据进行校验 4. 保留上次输入内容 5. 提供错误信息 二. 普通方式书写注册功能 ...
- 使用 lua 编写 wireshark 协议解析插件
一.平台 操作系统:windows 7 wireshark:1.10.3 lua:5.1 二.准备 lua 语言基本语法,特别是关于表操作和循环 wireshark 文档,包括用户使用文档和开发者文档 ...
- C语言考试
1.如何定义一个占用空间为0的变量 2.c++如何在指定内存区域创建对象 3.gcc动态库如何调用宿主执行文件的函数,阐述动态链接库的两种加载方式 4.static有什么用处 5.阐述do{...}w ...
- 121. Best Time to Buy and Sell Stock(动态规划)
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- crontab定时任务安装、使用方法
本文介绍下,在linux中安装crontab的方法,以及crontab的具体用法,有需要的朋友参考下. 这里使用yum方式安装crontab: 复制代码代码示例: [root@CentOS ~]# ...
- noip模拟赛 SAC E#1 - 一道中档题 Factorial
题目背景 数据已修改 SOL君(炉石主播)和SOL菌(完美信息教室讲师)是好朋友. 题目描述 SOL君很喜欢阶乘.而SOL菌很喜欢研究进制. 这一天,SOL君跟SOL菌炫技,随口算出了n的阶乘. SO ...