[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. ...
随机推荐
- vue之父子组件执行对方的方法
一.子组件执行父组件中的方法 1.父组件将方法名传给子组件,子组件进行调用 父组件中: <Vbutton typeBtn="success" :btnUserMethod=& ...
- List<Map<String,Object>> 中文排序
@RequestMapping(value = "/getBaseCodess", method = RequestMethod.GET) public ModelAndView ...
- NX二次开发-UFUN创建倒圆UF_MODL_create_blend
NX9+VS2012 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建块 UF_FEATURE_SIGN S ...
- UIWindow & UIWindowLevel笔记
一.UIWindow是一种特殊的UIView,通常在一个程序中只会有一个UIWindow,但可以手动创建多个UIWindow,同时加到程序里面.UIWindow在程序中主要起到三个作用: 1.作为容器 ...
- 关于CoreData的一个工具Mogenerator的使用
最近看到用CoreData时使用的工具Mogenerator,发现网上介绍其具体使用的不多,特此简单整理一下, 关于CoreData这里就不具体说了,使用就用MagicalRecord,用起来真是太方 ...
- mysql最新版与mysql5.6的兼容问题
最近公司在给别的企业打了一个项目,在公司本地使用的是mysql 5.6,但是搭建的项目的mysql版本是最新版5.7以后吧,所以有些sql在执行上出了一点问题 目前发现的是: 1: 在5.6版本下先o ...
- Python 爬虫-抓取小说《盗墓笔记-怒海潜沙》
最近想看盗墓笔记,看了一下网页代码,竟然不是js防爬虫,那就用简单的代码爬下了一节: """ 爬取盗墓笔记小说-七星鲁王宫 """ from ...
- POJ 2763 /// 基于边权的树链剖分
题目大意: 给定n个结点,有n-1条无向边,给定每条边的边权 两种操作,第一种:求任意两点之间路径的权值和,第二种:修改树上一点的权值. 因为是一棵树,可以直接把 u点和v点间(假设u为父节点,v为子 ...
- 006-Java的break和continue
break 和 continue关键字的使用 break: 结束当前循环 continue:结束当次循环 示例如下 class JavaTest{ public static void main(St ...
- 2019-8-31-C#-通过编程的方法在桌面创建回收站快捷方式
title author date CreateTime categories C# 通过编程的方法在桌面创建回收站快捷方式 lindexi 2019-08-31 16:55:58 +0800 201 ...