标签:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<limits.h>
#include<queue>
#include<stack>
using namespace std;
#define max(a, b) a>b?a:b
#define min(a, b) a<b?a:b
#define N 110
typedef struct maze
{
int a, b, c, step;
} MAZE;
int s, n, m, visit[N][N][N];
void BFS();
int main()
{
while(scanf("%d%d%d", &s, &n, &m), s+n+m)
{
if(s%2!=0)
printf("NO\n");
else
BFS();
}
return 0;
}
void BFS()
{
queue<MAZE>que;
memset(visit, 0, sizeof(visit));
MAZE p, q;
p.a=s;
p.b=0;
p.c=0;
p.step=0;
visit[p.a][p.b][p.c]=1;
que.push(p);
while(!que.empty())
{
p=que.front();
que.pop();
if((p.a==p.b&&p.c==0)||(p.a==p.c&&p.b==0)||(p.b==p.c&&p.a==0))
{
printf("%d\n", p.step);
return;
}
q=p;
if(p.a!=0)
{
if(p.a>n-p.b)//也就是说p.a还有剩余
{
//q= (MAZE) {p.a-n+p.b, n, p.c, p.step+1};
q.a=p.a-n+p.b;
q.b=n;
q.c=p.c;
q.step=p.step+1;
}
else
{
//q= (MAZE) {0, p.a+p.b, p.c, p.step+1};
q.a=