题意: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. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  2. Ubuntu 14.04 启用休眠

    Ubuntu 14.04 启用休眠 Ubuntu 14.04 默认不启用关机菜单中的休眠选项.前提是要有swap分区(网上查询,未验证是否一定需要.PS:swap要不小于物理内存)不过首先最好还是确认 ...

  3. PAT-乙级-1032. 挖掘机技术哪家强(20)

    1032. 挖掘机技术哪家强(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 为了用事实说明挖掘机技术到底 ...

  4. python datetime笔记

    python datetime笔记 http://mint-green.diandian.com/post/2011-09-09/4892024 获取当前时间,并通过字符串输出. 格式为:%Y-%m- ...

  5. 深入浅出ShellExecute

    Q: 如何打开一个应用程序? ShellExecute(this->m_hWnd,"open","calc.exe",""," ...

  6. 1964-NP

    描述 Problems in Computer Science are often classified as belonging to a certain class of problems (e. ...

  7. POJ1228+凸包

    见代码. /* 凸包(稳定凸包) 题意:给出一些点,这些点要么是凸包的顶点要么是边上的. 证明每条边上都至少有3个点. */ #include<stdio.h> #include<s ...

  8. linux Ubuntu12 设置root用户登录图形界面

    Ubuntu 12.04默认是不允许root登录的,在登录窗口只能看到普通用户和访客登录.以普通身份登陆Ubuntu后我们需要做一些修改,普通用户登录后,修改系统配置文件需要切换到超级用户模式,在终端 ...

  9. hbase集群 常用维护命令

    一. zk集群 1. 查看当前服务的角色 leader/follower echo stat|nc 127.0.0.1 2181 2.  启动ZK服务: sh bin/zkServer.sh star ...

  10. web.xml的说明

    <!--DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright 2000-2007 Sun Microsystems ...