B. Arpa’s obvious problem and Mehrdad’s terrible solution
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are some beautiful girls in Arpa’s land as mentioned before.

Once Arpa came up with an obvious problem:

Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that , where is bitwise xor operation (see notes for explanation).

Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.

Input

First line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the array and the integer x.

Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array.

Output

Print a single integer: the answer to the problem.

Examples
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
Note

In the first sample there is only one pair of i = 1 and j = 2. so the answer is 1.

In the second sample the only two pairs are i = 3, j = 4 (since ) and i = 1, j = 5 (since ).

A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR.

题意:
n个数,问这n个数中有几对数异或运算后结果是x。

代码:

 //c=a^b,a=c^b,b=a^c.用一个数组记录每个数出现的次数,每输入一个数将其与x异或运算得到的新数是否是前面输入过的,
//如果是,答案就加上该数出现的次数
#include<bits\stdc++.h>
using namespace std;
int a[],b[];
int main()
{
int n,x;
memset(b,,sizeof(b));
long long ans=;
scanf("%d%d",&n,&x);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
int tem=a[i]^x;
if(tem>) continue;//不会出现大于100000的数
ans+=b[tem];
b[a[i]]++;
}
printf("%lld\n",ans);
return ;
}
C. Arpa's loud Owf and Mehrdad's evil plan
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As you have noticed, there are lovely girls in Arpa’s land.

People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi.

Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows.

The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time.

Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible.

Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i).

Input

The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land.

The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush.

Output

If there is no t satisfying the condition, print -1. Otherwise print such smallest t.

Examples
Input
4
2 3 1 4
Output
3
Input
4
4 4 4 4
Output
-1
Input
4
2 1 4 3
Output
1
Note

In the first sample suppose t = 3.

If the first person starts some round:

The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1.

The process is similar for the second and the third person.

If the fourth person starts some round:

The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4.

In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa.

题意:

大小为n的数组a,a[i]表示从i点能一步到a[i]点,问有没有这样的一个最小的数t使得每一个a[i]满足从a[i]点走t步到a[j]点,从a[j]点走t步到达a[i]点。a[i]==i是允许的

代码:

 //枚举起点,如果从该点出发向下找,回不到到改点即在改点后面的某几个点之间循环说明无答案,如果从该点出发经过x步之后
//又回到了改点说明改点合法,如果x是奇数说明循环的点就是改点,如果x是偶数说明循环的点是改点和x/2处的某一点
//找出每个点需要的循环步数取最小公倍数就是答案。
#include<bits\stdc++.h>
using namespace std;
int gcd(int x,int y)
{
if(y==) return x;
return gcd(y,x%y);
}
int lcm(int x,int y)
{
return (x/gcd(x,y))*y;
}
int main()
{
int n,a[],vis[],ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
{
if(n==&&a[]!=) //只有一个点的情况特殊考虑
{ans=-;break;}
memset(vis,,sizeof(vis));
int x=i,tem=;
while(!vis[x])
{
vis[x]=;
x=a[x];
tem++;
}
if(x!=i) //如果从i点回到的是i后面的点就说明i点没有与之对应的点
{ans=-;break;}
if(tem&) ans=lcm(tem,ans);
else ans=lcm(tem/,ans);
}
printf("%d\n",ans);
return ;
}

CF2.BC的更多相关文章

  1. 数据库设计范式2——BC范式和第四范式

    我在很久之前的一篇文章中介绍了数据库模型设计中的基本三范式,今天,我来说一说更高级的BC范式和第四范式. 回顾 我用大白话来回顾一下什么是三范式: 第一范式:每个表应该有唯一标识每一行的主键. 第二范 ...

  2. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  3. bc:linux下命令行计算器

    在linux下,存在一个命令行的计算器:bc.该程序一般随发行版发布. bc计算器能够执行一些基本的计算,包括+,-,×,\,%. 这些计算不经针对十进制,还可以使用二进制,八进制,十六进制,并且可以 ...

  4. bc#29 做题笔记

    昨天的bc被坑惨了= = 本来能涨rating的大好机会又浪费了...大号已弃号 A:第一反应是高精度,结果模板找不到了= =,然后现学现卖拍了个java的BigInteger+快速幂,调了好半天不说 ...

  5. shell命令bc

    简介 bc支持浮点数的精度运算(Bash不支持浮点数运算) 运行方式 一.CLI 二.PIPE 示例 一.浮点数运算 变量scale:设置小数点后面的位数  # 默认scale=0 echo &quo ...

  6. windbg-bp、 bm、 bu、 bl、 bc、 ba(断点、硬件断点)

    bp bp 命令是在某个地址下断点, 可以 bp 0x7783FEB 也可以 bp MyApp!SomeFunction . 对于后者,WinDBG 会自动找到MyApp!SomeFunction 对 ...

  7. [推荐] BC/Beyond Compare(差异比较软件)

    Beyond Compare 前一段时间,介绍过用Total Commander来完成文件夹同步的时候,一位朋友留言推荐了Beyond Compare--一个强大的超越了文件差异比较的工具.Beyon ...

  8. echo "scale=100; a(1)*4" | bc -l 输出圆周率

    突然看到echo "scale=100; a(1)*4" | bc -l可以输出圆周率,很惊奇,后来发现很简单. 首先bc是“basic calculator”的缩写,就是初级的计 ...

  9. bc.34.B.Building Blocks(贪心)

    Building Blocks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

随机推荐

  1. 【安装Redis】CentOS7 下安装NodeJs+Express+MongoDB+Redis

    Redis,V3.2,官网l官方链接:http://www.redis.io/download,参考:http://blog.csdn.net/mlks_2008/article/details/19 ...

  2. 预处理指令 #import

    vs class # import会包含这个类的所有信息,包括实体变量和方法, # @class只是告诉编译器,其后面声明的名称是类的名称,至于这些类是如何定义的,先不考虑.

  3. 大数据系列-CDH环境中SOLR入数据

    1       创建集合 SSH远程连接到安装了SOLR的CDH节点. 运行solrctl  instancedir  --generate  /solr/test/GX_SH_TL_TGRYXX_2 ...

  4. Python爬虫Scrapy框架入门(3)

    往往需要爬取的网页是呈一个树状结构.比如,需要先爬取一个目录,然后再在目录中选择具体的爬取目标.而目录和具体目标之间,网页结构不同,使得我们不能使用相同的爬取策略. 从之前的经验来看,我们对scrap ...

  5. [BI项目记]-BUG创建

    BUG是在项目过程中以及运维过程中经常遇到的工作项.在处理每一个BUG的过程中,通过项目管理系统把BUG相应的内容纪录下来也是很重要的.这里将介绍如何通过TFS来完成BUG的创建工作. 首先我们来看B ...

  6. V4.0到来了,css雪碧图生成工具4.0更新啦

    V3.0介绍 http://www.cnblogs.com/wang4517/p/4476758.html V4.0更新内容 V4.0下载地址:http://download.csdn.net/det ...

  7. MachineKey 操作 之 应用集群中SSO应用生成MachineKey

    MachineKey介绍 MachineKey其用于对 Forms 身份验证 Cookie 数据和视图状态数据进行加密和解密,一般情况下IIS自动默认给网站或者每一个应用生成唯一的MachineKey ...

  8. 实时控制软件设计作业_01——汽车ABS系统分析

    制动防抱死系统(antilock brake system)简称ABS.作用就是在汽车制动时,自动控制制动器制动力的大小,使车轮不被抱死,处于边滚边滑(滑移率在20%左右)的状态,以保证车轮与地面的附 ...

  9. html学习第三天—— 第13,14章

    颜色值缩写 关于颜色的css样式也是可以缩写的,当你设置的颜色是16进制的色彩值时,如果每两位的值相同,可以缩写一半. 例子1: p{color:#000000;} 可以缩写为: p{color: # ...

  10. 修改radio与check样式

    一般的radio与check的样式很难看,这个时候就需要我们自己修改其样式 逻辑思维: 1.用label包裹input标签以及样式标签,然后将radio定位到界面以外,设置样式标签的样式 2.使用伪类 ...