题意:bc round 74 div1 1002 中文题

分析(官方题解):注意到答案实际上只和s⊕t有关, bfs预处理下从0到xx的最短步数, 然后查询O(1)回答即可.

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
typedef long long LL;
const int mod=1e9+;
const int N=2e5+;
vector<int>a;
queue<int>q;
int p[N];
int main()
{
int T,n,m;
scanf("%d", &T);
while(T--)
{
scanf("%d%d",&n,&m);
a.clear();
for(int i=;i<n;++i)
{
int tmp;
scanf("%d",&tmp);
a.push_back(tmp);
}
int l=log2(N);
l++;
for(int i=;i<=l;++i)
a.push_back((<<i));
memset(p,-,sizeof(p));
q.push();
p[]=;
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=;i<a.size();++i)
{
int y=(x^a[i]);
if(y>N-||p[y]!=-)continue;
p[y]=p[x]+;
q.push(y);
}
}
LL ans=;
for(int i=;i<=m;++i)
{
int s,t;
scanf("%d%d",&s,&t);
LL x=i,y=p[s^t];
ans=(ans+x*y%mod)%mod;
}
printf("%I64d\n",ans);
}
return ;
}

HDU 5637 Transform 搜索的更多相关文章

  1. HDU 5637 Transform 单源最短路

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5637 题意: http://bestcoder.hdu.edu.cn/contests/contes ...

  2. HDU 5637 Transform

    题意: 有两种变换: 1. 改变此数二进制的某一位(1变成0 或者 0变成1) 2. 让它与给出的n个数当中的任意一个做异或运算 给你两个数s, t,求从s到t最少要经过几步变换,一共m组查询思路: ...

  3. hdu 5637 Transform 最短路

    题目链接 异或的性质. 求s到t的最少步骤, 等价于求0到s^t的最少步骤. 通过最少的步骤达到s^t的状态, 等价于求0到s^t的最短路. 先将最短路求出来然后O(1)查询. #include &l ...

  4. hdu 5637 BestCoder Round #74 (div.2)

    Transform  Accepts: 7  Submissions: 49  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 131072 ...

  5. hdu 5468(莫比乌斯+搜索)

    hdu 5468 Puzzled Elena   /*快速通道*/ Sample Input 5 1 2 1 3 2 4 2 5 6 2 3 4 5   Sample Output Case #1: ...

  6. HDU 4499.Cannon 搜索

    Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

  7. HDU 1045 (DFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...

  8. HDU 1180 (BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...

  9. HDU 2531 (BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...

随机推荐

  1. 关于java中sizeof的问题

    因为java没有提供现成的函数去计算对象的内存空间,不过可以用大量产生某个对象然后计算平均值的方法近似获得该对象占用的内存. 虽然这种方法不是很准,但是也在一定程度上计算出来了对象所占用的内存空间,下 ...

  2. POJ1734 - Sightseeing trip

    DescriptionThere is a travel agency in Adelton town on Zanzibar island. It has decided to offer its ...

  3. c++ 16 this 和 继承 及继承机制中的构造函数 与 析构函数

    #include <iostream> #include <string> using namespace std; class Animal { public: Animal ...

  4. hibernate中session

    hibernate中的session是一级缓存,可以理解为进程级的缓存.在进程运行期间一直存在. session可以理解为一个可以操作数据库的对象 具体如何操作数据库? session中有方法, 如果 ...

  5. unity 3d 获取鼠标当前坐标

    获取当前鼠标position:Input.mousePosition;

  6. hdu 3631

    最短路  执行一遍 Floyd算法    比赛的时候没有想到, 用了优化的Dijkstra  超时到死 #include <cstdio> #include <cstring> ...

  7. ural 1200

    推出公式  然后特判两端  代码其实挺烂      但是有人竟然可以直接暴过去的 ...... #include <cstdio> #include <cstring> #in ...

  8. 安装ADT Cannot complete the install because one or more required items could not be found.

    点击进行安装,将会弹出 错误提示是: Cannot complete the install because one or more required items could not be found ...

  9. Otto开发初探——微服务依赖管理新利器

    [编者按]时下,Vagrant 被 DevOps 软件开发商广泛作为开发阶段的本地软件开发环境,而在本文,CERT Division高级研究员介绍的 Otto 则是 Vagrant 开发团队 Hash ...

  10. hdu 4559 涂色游戏 博弈论

    构造SG函数:sg[i]表示2*i的sg值!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm ...