RT
que里的head 莫名奇妙的自己增加,爆掉了,大佬勿喷。
#include<iostream>
#include<string.h>
using namespace std;
int T;
int C_A,C_B,N;
struct water{
int a;
int b;
}queue[3048];
int last[3048],pus[3048];
bool mark[1024][1024];
void back(int x)
{
if(!last[x])return;
back(last[x]);
cout<<pus[x]<<" ";
}
void bfs()
{
memset(queue,0,sizeof(queue));
int head=0;
int tail=1;
queue[tail].a=0;
queue[tail].b=0;
mark[queue[tail].a][queue[tail].b]=1;
int tx,ty;
while(1)
{
head++;
cout<<head<<endl;
int lx=queue[head].a;
int ly=queue[head].b;
tx=queue[head].a;
ty=queue[head].b;
tx=C_A;
if(!mark[tx][ty])
{
mark[tx][ty]=1;
tail++;
queue[tail].a=tx;
queue[tail].b=ty;
last[tail]=head;
pus[tail]=1;
if(queue[tail].a==N)
{back(tail);cout<<endl;break;}
}
tx=queue[head].a;
ty=queue[head].b;
ty=C_B;
if(!mark[tx][ty])
{
mark[tx][ty]=1;
tail++;
queue[tail].a=tx;
queue[tail].b=ty;
last[tail]=head;
pus[tail]=2;
if(queue[tail].b==N)
{back(tail);cout<<endl;break;}
}
tx=queue[head].a;
ty=queue[head].b;
tx=0;
if(!mark[tx][ty])
{
mark[tx][ty]=1;
tail++;
queue[tail].a=tx;
queue[tail].b=ty;
last[tail]=head;
pus[tail]=3;
}
tx=queue[head].a;
ty=queue[head].b;
ty=0;
if(!mark[tx][ty])
{
mark[tx][ty]=1;
tail++;
queue[tail].a=tx;
queue[tail].b=ty;
last[tail]=head;
pus[tail]=4;
}
tx=queue[head].a;
ty=queue[head].b;
if(tx>(C_B-ty))
{ty=C_B;tx-=(C_B-ty);}
else
{ty+=tx;tx=0;}
if(!mark[tx][ty])
{
mark[tx][ty]=1;
tail++;
queue[tail].a=tx;
queue[tail].b=ty;
last[tail]=head;
pus[tail]=6;
if(queue[tail].a==N||queue[tail].b==N)
{back(tail);cout<<endl;break;}
}
tx=queue[head].a;
ty=queue[head].b;
if(ty>(C_A-tx))
{tx=C_A;ty-=(C_A-tx);}
else
{tx+=ty;ty=0;}
if(!mark[tx][ty])
{
mark[tx][ty]=1;
tail++;
queue[tail].a=tx;
queue[tail].b=ty;
last[tail]=head;
pus[tail]=5;
if(queue[tail].a==N||queue[tail].b==N)
{back(tail);cout<<endl;break;}
}
}
}
int main(void)
{
cin>>T;
while(T--)
{
cin>>C_A>>C_B>>N;
bfs();
}
return 0;
}