#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct node
{
int x;
int s;
};
bool prim[];
bool vis[];
int chr(int x,int i,int j)
{
int b,s = ;
int tmp = ;
for(int z = ; z<= ; z++)
{
b = x%;
x/=;
if(i==z) b = j;
tmp+=s*b;
s*=;
}
return tmp;
}
int main()
{
// freopen("in.in","r",stdin);
for(int i = ; i <= ; i++)
{
if(prim[i]) continue;
for(int j = ; j <= /i; j++)
prim[i*j] = true;
}
queue<node>q;
node s, t;
int n, a, b, tmp;
bool flag;
scanf("%d",&n);
while(n--)
{
flag = false;
memset(vis,false,sizeof(vis));
scanf("%d%d",&a,&b);
s.x = a;
s.s = ;
q.push(s);
while(q.size())
{
s = q.front();
q.pop();
t.s = s.s + ;
vis[s.x] = true;
if(s.x == b)
{
flag = true;
break;
}
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
{
if(i== && j==) continue;
t.x = chr(s.x,i,j);
if(prim[t.x] || vis[t.x]) continue;
q.push(t);
}
}
while(q.size()) q.pop();
if(flag) cout<<s.s<<endl;
else cout<<"Impossible"<<endl;
}
return ;
}

[kuangbin带你飞]专题一 简单搜索 - F - Prime Path的更多相关文章

  1. [kuangbin带你飞]专题一 简单搜索 题解报告

    又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...

  2. [kuangbin带你飞]专题一 简单搜索(回顾)

    A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...

  3. [kuangbin带你飞]专题一 简单搜索 - E - Find The Multiple

    //Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余 ...

  4. [kuangbin带你飞]专题一 简单搜索 棋盘问题

    题来:链接https://vjudge.net/problem/OpenJ_Bailian-132 J - 棋盘问题 1.题目: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别. ...

  5. [kuangbin带你飞]专题一 简单搜索

            ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题   328 / 854 Problem B POJ 2251 Dungeon Ma ...

  6. [kuangbin带你飞]专题一 简单搜索 回顾总结

    第二题:bfs,忘了将queue清空. 第三题:bfs,记得使用vis数组,防止重复入队

  7. 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  8. [kuangbin带你飞]专题一 简单搜索 Find a way HDU - 2612

    Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year ...

  9. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

随机推荐

  1. 字符串利用%02d将月份前加0

    i = 20190104 a = 2019 b = 1 c = 4 s = "%04d-%02d-%02d" % (a, b, c)

  2. ajax 工作原理

    Ajax的优缺点及工作原理? 定义和用法: AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML).Ajax 是一种用于创建快速动态网 ...

  3. Linux 系统 /var/log/journal/ 垃圾日志清理

    CentOS系统中有两个日志服务,分别是传统的 rsyslog 和 systemd-journal systemd-journald是一个改进型日志管理服务,可以收集来自内核.系统早期启动阶段的日志. ...

  4. idea-----idea中“cannot resolve symbol servlet”的解决

    原文章链接: 传送器>>>>>>>>>>>>>>>>. 第一次使用IntelliJ IDEA时我遇到了& ...

  5. vue组件添加鼠标滚动事件

    在一个组件标签上加鼠标滚动事件,应该写成    @mousewheel.native

  6. leetcood学习笔记-257-二叉树的所有路径

    题目描述: 第一次提交:参考113-路径总和② class Solution: def binaryTreePaths(self, root: TreeNode) -> List[str]: r ...

  7. Tomcat 调优的技巧

    转载:www.cnblogs.com/wangsen, https://mp.weixin.qq.com/s/WrIsOOyR7o4SwSXMT0Zecg 最近,看到一篇讲述 Tomcat 调优的文章 ...

  8. 6 Accessing and Managing Symbols with armlink

    6.4 Image$$ execution region symbols The linker generates Image$$ symbols for every execution region ...

  9. 把Debian 设置中文环境

    要支持区域设置,首先要安装locales软件包: apt-get install locales 然后配置locales软件包: dpkg-reconfigure locales 在界面中钩选上“zh ...

  10. python批量运行py文件

    import os path="E:\\python" #批量的py文件路径 for root,dirs,files in os.walk(path): #进入文件夹目录 for ...