|
为什么一个数据中第二个数据就都是0了呢???
- #include<iostream>
- using namespace std;
- int t,i,j,k,v;
- const int mx=100010;
- const int mm=2010;
- const int tt=35;
- int n[mx],a[mx],b[mx],f[mm][mm];///n次数
- int ka[tt],kb[tt],kn[tt];
- bool bb[mm][mm],bbb;///f情况
- int head,tail,va,vb,nn;
- void cle()///clear
- {
- for (int ic=0; ic<=mx-2; ic++)
- {
- a[ic]=0,b[ic]=0,n[ic]=0;
- }
- for (int ic=1; ic<=mm-2; ic++)
- for (int id=1; id<=mm-2; id++)
- {
- f[ic][id]=0,bb[ic][id]=0;
- }
- head=1,tail=2,bbb=true;
- }
- void pp()
- {
- for (int ii=1; ii<=10; ii++)
- cout<<a[ii]<<" "<<b[ii]<<" "<<n[ii]<<endl;
- }
- void pp2()
- {
- for (k=1;k<=10;k++)
- for (v=1;v<=10;v++) cout<<bb[k][v];
- }
- int main()
- {
- cin>>t;
- for (int it=1; it<=t; it++)
- {
- cin>>ka[it]>>kb[it]>>kn[it];
- va=ka[it],vb=kb[it],nn=kn[it];///va,vb容量 nn B中目标水量
- cle();///pp2();
- ///cout<<head<<" "<<tail<<" "<<va<<" "<<vb<<" "<<nn<<" ";
- while (head<=tail&&bbb)
- {
- ///目前搜索head
- if (b[head]==nn)
- {
- cout<<n[head]<<" ";
- for (int ib=1; ib<=n[head]; ib++) cout<<f[head][ib]<<" ";
- cout<<endl;
- bbb=false;
- }
- for (i=1; i<=6&&bbb; i++)
- {
- if (i==1&&a[head]!=va&&!bb[va][b[head]])
- {
- n[tail]=n[head]+1;
- a[tail]=va;
- b[tail]=b[head];
- bb[va][b[head]]=true;
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- if (i==2&&b[head]!=vb&&!bb[a[head]][vb])
- {
- n[tail]=n[head]+1;
- b[tail]=vb;
- a[tail]=a[head];
- bb[a[head]][vb]=true;
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- if (i==3&&a[head]!=0&&!bb[0][b[head]])
- {
- n[tail]=n[head]+1;
- a[tail]=0;
- b[tail]=b[head];
- bb[a[head]][vb]=true;
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- if (i==4&&b[head]!=0&&!bb[a[head]][0])
- {
- n[tail]=n[head]+1;
- b[tail]=0;
- a[tail]=a[head];
- bb[a[head]][vb]=true;
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- if (i==5&&b[head]!=0&&!bb[a[head]+b[head]][0])
- {
- bb[a[head]+b[head]][0]=true;
- if (va-a[head]>=b[head])///B倒完了
- {
- n[tail]=n[head]+1;
- b[tail]=0;
- a[tail]=a[head]+b[head];
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- else
- {
- n[tail]=n[head]+1;
- a[tail]=va;
- b[tail]=b[head]-(va-a[head]);
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- }
- if (i==6&&a[head]!=0&&!bb[0][a[head]+b[head]])
- {
- bb[0][a[head]+b[head]]=true;
- if (vb-b[head]>=a[head])///A倒完了
- {
- n[tail]=n[head]+1;
- a[tail]=0;
- b[tail]=b[head]+a[head];
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- else
- {
- n[tail]=n[head]+1;
- a[tail]=a[head]-(vb-b[head]);
- b[tail]=vb;
- for (j=1; j<=n[head]; j++) f[tail][j]=f[head][j];
- f[tail][n[tail]]=i;
- tail++;
- }
- }
- }
- pp();
- head++;
- }
- }
- return 0;
- }
复制代码 |
|