/* 错了23次才AC的,一开始MLE, TLE,最后改成wrong,一路很艰辛,但是是有收获的 一开始把状态保存错了,写的很烂的代码,以后再优化吧。。 假设 A B C(A == B + C) A -> B A -> C B -> C B -> A C -> A C -> B */ #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; struct node { int s, n , m, step; node(){}; node(int a, int b, int c, int d):s(a), n(b), m(c), step(d){}; }; int s, n, m; bool hash[101][101][101]; void BFS() { queue<node>Q; node now, next; int temp = s / 2; Q.push(node(s, 0, 0, 0)); memset(hash, false, sizeof(hash)); hash[s][0][0] = true; while(!Q.empty()) { now = Q.front(); Q.pop(); if(now.s == temp && now.n == temp || now.s == temp && now.m == temp || now.n == temp && now.m == temp) { printf("%d/n", now.step); return ; } if(now.s > n - now.n) { next = now; next.s = now.s - (n - now.n); next.n = now.n + (n - now.n); next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.s <= n - now.n) { next = now; next.s = now.s - now.s; next.n = now.n + now.s; next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.s > m - now.m) { next = now; next.s = now.s - (m - now.m); next.m = now.m + (m - now.m); next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.s <= m - now.m) { next = now; next.s = now.s - now.s; next.m = now.m + now.s; next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.m > s - now.s) { next = now; next.s = now.s + (s - now.s); next.m = now.m - (s - now.s); next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.m <= s - now.s) { next = now; next.s = now.s + now.m; next.m = now.m - now.m; next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.m > n - now.n) { next = now; next.n = now.n + (n - now.n); next.m = now.m - (n - now.n); next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.m <= n - now.n) { next = now; next.n = now.n + now.m; next.m = now.m - now.m; next.step = now.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.n > m - now.m) { next = now; next.m = next.m + (m - now.m); next.n = next.n - (m - now.m); next.step = next.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.n <= m - now.m) { next = now; next.m = next.m + now.n; next.n = next.n - now.n; next.step = next.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.n > s - now.s) { next = now; next.s = next.s + (s - now.s); next.n = next.n - (s - now.s); next.step = next.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } if(now.n <= s - now.s) { next = now; next.s = next.s + now.n; next.n = next.n - now.n; next.step = next.step + 1; if(!hash[next.s][next.n][next.m]) { hash[next.s][next.n][next.m] = true; Q.push(next); } } } printf("NO/n"); return ; } int main() { while(scanf("%d %d %d", &s, &n, &m) != EOF && n+ m + s) { if(s & 1) { puts("NO"); continue; } if(n == s / 2) { printf("1/n"); continue; } BFS(); } }