poj3126--Prime Path(广搜)】的更多相关文章

题目: 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,…
POJ3126 Prime Path 一开始想通过终点值双向查找,从最高位开始依次递减或递增,每次找到最接近终点值的素数,后来发现这样找,即使找到,也可能不是最短路径, 而且代码实现起来特别麻烦,后来搜了一下解题报告,才发现是bfs(). 想想也是,题目其实已经提示的很清楚了,求最短的路径,对于每一个数,每次可以把4位中的任意一位,  换成与该位不相同的0-9中的任意一位,对于迷宫类 bfs每次转移数为上下左右四个状态,而此题就相当于每次可以转移40个状态(其实最低位为偶数可以排除,不过题目数据…
非常水的一道广搜题(专业刷水题). .. #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   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…
Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11751   Accepted: 6673 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-dig…
题目链接: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;…
  POJ 3126  Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16204   Accepted: 9153 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…
题意:一个四位数的质数,每次只能变换一个数字,而且变换后的数也要为质数.给出两个四位数的质数,输出第一个数变换为第二个数的最少步骤. 利用广搜就能很快解决问题了.还有一个要注意的地方,千位要大于0.例如0373这个数不符合要求. #include <iostream> #include <cstdio> #include <queue> #include <cmath> #include <map> using namespace std; st…