题目:
#include<stdio.h>
#include<queue>
using namespace std;
struct N{
int a,b,c;
int t;
};
queue<N> Q;
bool mark[101][101][101];
void AtoB(int &a,int sa,int &b,int sb){
//两杯子容积分别为sa ,sb
//两杯子里原有可乐体积 a ,b
//?不加&会怎样
if(sb-b>=a)//a可以全部倒进b中
{
b+=a;
a=0;
}
else{
a-=sb-b;
b=sb;
}
}
int BFS(int s,int n,int m){
while(Q.empty()==false){
//当队列非空
N now=Q.front();//拿出队头状态
Q.pop();//弹出队头状态
int a,b,c;//临时保存三个杯子中的可乐
a=now.a;
b=now.b;
c=now.c;
AtoB(a,s,b,n);//由a倾倒向b
if(mark[a][b][c]==false){
//若该体积组尚未标记
mark[a][b][c]=true;
N tmp;
tmp.a=a;
tmp.b=b;
tmp.c=c;
tmp.t=now.t+1;//生成新的状态
if(a==s/2&&b==s/2) ret