[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. ...
随机推荐
- windows下安装jenkins初级(2)
这里是基于gitlab拉取代码 gitlab暂时先不多介绍 我们需要把git和gitlab连接起来方便拉取代码 所以需要git的ssh公匙和私匙 首先在 https ...
- 三种Spring加载机制
方法一. 在main方法中启动Spring ApplicationContext ac = new XmlApplicationContext("applicationContext.xml ...
- struts2-convention-plugin零配置
零配置的意思并不是说没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少. <?xml version="1.0" encoding=&quo ...
- hdu6606多校第四次04——线段树加速dp
/* 首先想到二分答案,难点在于如何判断是否有K段,每段和<=mid 把问题转化成求最多有R段,最少有L段,每段的的和<=mid,如果 L<=K<=R 那么显然存在把这个序列分 ...
- LUOGU P3723 [AH2017/HNOI2017]礼物 (fft)
传送门 解题思路 首先我们设变化量为\(r\),那么最终的答案就可以写成 : \[ ans=min(\sum\limits_{i=1}^n(a_i-b_i+r)^2) \] \[ ans=min(\s ...
- 码云挂了,无法访问gitee
解决方式1.修改dns为114.114.114.114 2.hosts文件添加212.64.62.174 gitee.com
- NX二次开发-UFUN圆弧矩阵标记、起始角和结束角(弧度测量)、圆弧中心坐标和圆弧半径UF_CURVE_ask_arc_data(边可以用)
1 NX11+VS2013 2 3 #include <uf.h> 4 #include <uf_ui.h> 5 #include <uf_modl.h> 6 #i ...
- document.body / document.ducumentElement /等获取高度和宽度的区别
document.body / document.ducumentElement /等获取高度和宽度的区别 <!DOCTYPE html> <html> <head la ...
- JVM内核-原理、诊断与优化学习笔记(五):GC参数
文章目录 堆的回顾 串行收集器 并行收集器 ParNew(par-并行的缩写,new-新生代,所以只是新生代并行) Parallel收集器 参数设置 -XX:MaxGCPauseMills -XX:G ...
- Jeecg 容器初始化监听器
文件位置: F:\jeecg-bpm-3.8\jeecg-bpm-3.8-master\jeecg-bpm-3.8\src\main\java\org\jeecgframework\web\syste ...