#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. 5. java运算符

    1.算术运算符 注意: % 取余数 (1)自增 (++)前自增:先自增完毕,再运算整个表达式,语句分号前面的都是运算表达式: 后自增,先运算完整个表达式(分号前面的都是表达式),再进行自增: 2.赋值 ...

  2. SOLID设计原则

    SOLID设计原则 Single Responsibility Principle单一职责原则 单一职责原则(SRP)表明一个类有且只有一个职责. 一个类就像容器一样,它能添加任意数量的属性.方法等. ...

  3. charles抓取数据

    charles抓包 抓取手机app的数据 charles设置 help--->SSL Proxying--->Install Charles Root Certificate 1.给电脑下 ...

  4. FFmpeg Download

    https://ffmpeg.zeranoe.com/builds/

  5. 字符串hash+回文树——hdu6599

    拖了很久才补的回文树,感觉网上的博客都是一个做法..回文树统计不同种类的回文串出现次数,然后用字符串hash来判每个回文子串是否符合要求 #include<bits/stdc++.h> u ...

  6. 58 matlab 编程

    0 引言 matlab中有些东西记录一下 1 matlab coder matlab命令行窗口输入: coder 回车即可打开matlab coder 窗口.接着,matlab将引导你把matlab格 ...

  7. NX二次开发-弹出选择文件夹对话框

    这个UFUN和NOPEN里没有对应的函数和类,要用C++的方法去做. #include "afxdialogex.h"//弹出选择文件夹对话框头文件 #include " ...

  8. 秦曾昌人工智能课程---6、Decision Tree Learning

    秦曾昌人工智能课程---6.Decision Tree Learning 一.总结 一句话总结: 怎样去构建决策树:比如一维:***|00|***|000|***,|为分割线,每个分割点都是一种情况, ...

  9. Comparison of FastText and Word2Vec

    Comparison of FastText and Word2Vec   Facebook Research open sourced a great project yesterday - fas ...

  10. OAuth2.0的理解-转自阮一峰博客

    一.应用场景 为了理解OAuth的适用场合,让我举一个假设的例子. 有一个"云冲印"的网站,可以将用户储存在Google的照片,冲印出来.用户为了使用该服务,必须让"云冲 ...