HDU 5637 Transform 搜索
2016-03-06 10:36
295 查看
题意:bc round 74 div1 1002 中文题
分析(官方题解):注意到答案实际上只和s⊕t有关, bfs预处理下从0到xx的最短步数, 然后查询O(1)回答即可.
View Code
分析(官方题解):注意到答案实际上只和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+7; const int N=2e5+5; vector<int>a; queue<int>q; int p ; int main() { int T,n,m; scanf("%d", &T); while(T--) { scanf("%d%d",&n,&m); a.clear(); for(int i=0;i<n;++i) { int tmp; scanf("%d",&tmp); a.push_back(tmp); } int l=log2(N); l++; for(int i=0;i<=l;++i) a.push_back((1<<i)); memset(p,-1,sizeof(p)); q.push(0); p[0]=0; while(!q.empty()) { int x=q.front(); q.pop(); for(int i=0;i<a.size();++i) { int y=(x^a[i]); if(y>N-5||p[y]!=-1)continue; p[y]=p[x]+1; q.push(y); } } LL ans=0; for(int i=1;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 0; }
View Code
相关文章推荐
- 工厂模式理解
- 自学 java 笔记 day9(继承下)
- leetcode:Best Time to Buy and Sell Stock II 【Java】
- CentOS 7 配置163源
- linux安全第二周总结
- Python切片知识解析
- [Unity优化]数据的加密与解密
- SQL读书笔记(九) UNION
- hihoCoder#1032 : 最长回文子串(manacher算法)
- kidd风的IOS日志之地图与定位
- Android中百度地图的使用方法之覆盖物功能(一)
- Kiss you goodbye
- 简单的验证码实现
- 分治法——归并排序
- 从无重复大数组找TOP N元素的最优解说起
- html5中链接和分组标签
- Krustral 算法
- 蓝桥杯-幸运数(模拟)
- [译]信仰是怎样毁掉程序猿的How religion destroys programmers
- HDU 4506 小明系列故事——师兄帮帮忙(快速幂)