Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 奇怪的错误。。。

Posted by liuyuhui at 2017-05-19 11:00:42 on Problem 3126
```在我加注释的那一行，如果不是在bfs中直接输出，而是返回值，就会WA
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;
const int maxn = 10000;
bool IsPrime[maxn];
int s, e;
bool used[maxn];
struct point {
int x;
int s;
point(int x, int s) : x(x), s(s) {}
};
void sieve(int n) {
for (int i = 0; i <= n; i++)
IsPrime[i] = true;
IsPrime[0] = IsPrime[1] = false;
for (int i = 2; i <= n; i++) {
if (IsPrime[i]) {
for (int j = i * 2; j <= n; j += i)
IsPrime[j] = false;
}
}
}
int bfs() {
queue<point> q;
q.push(point(s, 0));
used[s] = true;
while (!q.empty()) {
point tmp = q.front();
q.pop();
if (tmp.x == e)
cout << tmp.s << endl;//return tmp.s;
for (int i = 1; i <= 1000; i *= 10) {
int num = tmp.x;
num /= i;
num %= 10;
int w = tmp.x - num * i;
for (int j = 0; j < 10; j++) {
if (!(i == 1000 && j == 0)) {
int currNum = w + j * i;
if (currNum != num && IsPrime[currNum] && !used[currNum]) {
q.push(point(currNum, tmp.s + 1));
used[currNum] = true;
}
}
}
}
}
}
int main() {
int n;
cin >> n;
sieve(maxn);
while (n--) {
cin >> s >> e;
memset(used, false, sizeof(used));
bfs();
}
}```

Followed by: