[kuangbin带你飞]专题一 简单搜索 - F - Prime Path
#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的更多相关文章
- [kuangbin带你飞]专题一 简单搜索 题解报告
又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...
- [kuangbin带你飞]专题一 简单搜索(回顾)
A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...
- [kuangbin带你飞]专题一 简单搜索 - E - Find The Multiple
//Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余 ...
- [kuangbin带你飞]专题一 简单搜索 棋盘问题
题来:链接https://vjudge.net/problem/OpenJ_Bailian-132 J - 棋盘问题 1.题目: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别. ...
- [kuangbin带你飞]专题一 简单搜索
ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题 328 / 854 Problem B POJ 2251 Dungeon Ma ...
- [kuangbin带你飞]专题一 简单搜索 回顾总结
第二题:bfs,忘了将queue清空. 第三题:bfs,记得使用vis数组,防止重复入队
- 迷宫问题 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, ...
- [kuangbin带你飞]专题一 简单搜索 Find a way HDU - 2612
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
随机推荐
- table 表头不动,tbody滚动对齐
http://www.imaputz.com/cssStuff/bigFourVersion.html# https://blog.csdn.net/yiifaa/article/details/52 ...
- .nett Core之路由配置
//配置路由 app.UseMvc(buider => { buider.MapRoute("Default", "{controller=home}/{actio ...
- Delphi 字符串函数 StrUtils(大全)
引用单元: StrUtils; 首部 function AnsiResemblesText(const AText, AOther: string): Boolean; $[StrUtils.pas ...
- bzoj_auto_submiter(辣鸡Py毁我青春系列)
听说你们的bzoj小号都很厉害? 不如试试bzoj金坷垃——bzoj_auto_submiter! 把所有的代码拖进解压后的文件夹,然后双击run.cmd. 看到有chrome浏览器窗口弹出来不要慌, ...
- cdh maven仓库地址
常用的maven仓库地址: 中央库:http://repo.maven.apache.org/maven2/ cdh库:https://repository.cloudera.com/artifact ...
- PMP项目管理——项目范围管理
项目范围管理包括确保项目做且只做所需的全部工作,以成功完成项目的各个过程.项目范围管理主要在于定义和控制哪些工作应该包括在项目内,哪些不应该包括在项目内. 项目范围管理过程包括: 1 规划范围管理—— ...
- Excel的数据分析—排位与百分比
Excel的数据分析-排位与百分比 某班级期中考试进行后,按照要求仅公布成绩,但学生及家长要求知道排名.故欲公布成绩排名,学生可以通过成绩查询到自己的排名,并同时得到该成绩位于班级百分比排名(即该同学 ...
- websokect的原理
WebSocket 机制 以下简要介绍一下WebSocket的原理及运行机制. WebSocket是HTML5下一种新的协议.它实现了浏览器与服务器全双工通信,能更好的节省服务器资源和带宽并达到实时通 ...
- pop&dismiss
//dismiss到根视图 - (void)dismissToRootViewController{ UIViewController *vc = self; while (vc.presenting ...
- 随笔记录 grub引导故障修复 2019.8.7
系统备份: [root@localhost ~]# mkdir /abc [root@localhost ~]# mount /dev/sdb1 /abc [root@localhost ~]# dd ...