题意: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. csharp excel interop programming

    string fileName = "c:\\a.xlsx"; var application = new Application(); application.Visible = ...

  2. Mapped Statements collection does not contain value for ResearcherMapper.方法名

    搞了半天, 原来是映射文件没加, 新手常遇到的问题. Mapped Statements collection does not contain value for后面是什么类什么方法之类的: 错误原 ...

  3. 4.4 spring-自定义标签的解析

    1.0 自定义标签的解析. 在之前的章节中,我们完成了对spring 默认标签的加载过程.那么现在我们将开始新的里程, spring 自定义标签的解析; 代码如下: /** * Parse the e ...

  4. Hex string convert to integer with stringstream

    #include <sstream>#include <iostream>int main() { unsigned int x; std::stringstream ss; ...

  5. nginx 详解

    #运行用户 #user  nobody;   #启动进程,通常设置成和cpu的数量相等或者2倍于cpu的个数(具体结合cpu和内存).默认为1 worker_processes  1;   #全局的错 ...

  6. Eclipse中安装使用SVN

    参考网址: Eclipse中使用SVN - 流逝的是岁月,沉淀的是经典 - 博客频道 - CSDN.NET http://blog.csdn.net/v123411739/article/detail ...

  7. 179. Largest Number

    题目: Given a list of non negative integers, arrange them such that they form the largest number. For ...

  8. Fundamental Datastructure

    11988 - Broken Keyboard (a.k.a. Beiju Text) 可以用deque来模拟. #include <iostream> #include <stri ...

  9. R语言学习笔记:怎么从txt中读入数据

    1   从该链接中下载测试数据,http://pan.baidu.com/share/link?shareid=3322971616&uk=3862050759   2   把测试文件Anal ...

  10. 如何在VS2010中使用Async功能?

    伴随C#5.0的发布,“异步”特性越来越深入人心:在VS2012中早就可以使用它大大简化异步编程的痛苦,那么在VS2010中呢?我们无法尝鲜么?答案是“No”!,其实我们可以这样做: 1)必须把你的V ...