POJ3126 Prime Path】的更多相关文章

POJ3126 Prime Path 一开始想通过终点值双向查找,从最高位开始依次递减或递增,每次找到最接近终点值的素数,后来发现这样找,即使找到,也可能不是最短路径, 而且代码实现起来特别麻烦,后来搜了一下解题报告,才发现是bfs(). 想想也是,题目其实已经提示的很清楚了,求最短的路径,对于每一个数,每次可以把4位中的任意一位,  换成与该位不相同的0-9中的任意一位,对于迷宫类 bfs每次转移数为上下左右四个状态,而此题就相当于每次可以转移40个状态(其实最低位为偶数可以排除,不过题目数据…
题目: The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter of security to change such things every now and then,…
Prime Path   Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of security to change such thin…
题目链接:http://poj.org/problem?id=3126 Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22936   Accepted: 12706 Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they…
http://poj.org/problem?id=3126 题目大意:给两个数四位数m, n, m的位数各个位改变一位0 —— 9使得改变后的数为素数, 问经过多少次变化使其等于n 如: 1033173337333739377987798179 分析:用字符串存m,n,这样改变各个位较方便 数组开大一点,开始数组开小了,结果就出错了 #include<stdio.h> #include<stdlib.h> #include<math.h> #include<qu…
题目链接. AC代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <queue> #include <algorithm> #include <map> #include <ctype.h> using namespace std;…
非常水的一道广搜题(专业刷水题). .. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #define inf 1000000 using namespace std; int d[4]={1,10,100,1000}; int vis[10000]; int prime[10000]; int q[inf]; int n1,n2; void isprime() {…
题目链接:Prime Path 题目大意 从一个四位素数m开始,每次只允许变动一位数字使其变成另一个四位素数.求最终把m变成n所需的最少次数. 思路 BFS.搜索的时候,最低位为0,2,4,6,8可以先排除(偶数不会是素数),最高位是0的也可以排除.这个题判断素数的次数比较少,可以不打素数表. 题解 第二次写的时候代码写的很乱..没有第一遍干净了 #include <iostream> #include <cstring> #include <queue> using…
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of security to change such things every now and then, to…
Prime Path DescriptionThe ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter of security to change such things e…