USACO:Mother's Milk

广搜即可

/*
ID: Jang Lawrence
PROG: milk3
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
bool is[21][21][21];
bool in[21];
struct ps
{
    int a[3];
    void f(){is[a[0]][a[1]][a[2]]=1;}
    bool g(){return is[a[0]][a[1]][a[2]];}
}now,v,t;
int b[3];
queue<ps>  q;
void pour(ps &x,int i,int j)
{
    int &ai=x.a[i],&aj=x.a[j];
    int y=b[j]-aj;
    if(y==0) return ;
    if(y>ai)  {aj=ai+aj;ai=0;}
    else  {aj+=y;ai-=y;}
}
int main()
{
    #ifndef  DEBUG
  freopen("milk3.in","r",stdin);
  freopen("milk3.out","w",stdout);
  #endif
  scanf("%d%d%d",&b[0],&b[1],&b[2]);
  now.a[0]=0;
  now.a[1]=0;
  now.a[2]=b[2];
  now.f();
  q.push(now);
  while(!q.empty())
  {
      v=q.front();
      q.pop();
      if(v.a[0]==0)in[v.a[2]]=1;
     for(int i=0;i<3;++i)
     for(int j=0;j<3;++j)
    if(i!=j)
    {
        t=v;
        pour(t,i,j);
        if(t.g());
        else  {q.push(t);t.f();}
    }
  }
  for(int i=0;i<=b[2];++i)
  if(in[i]){
      printf("%d",i);
      if(i==b[2]) puts("");
      else  putchar(' ');
  }
  return 0;
}


你可能感兴趣的:(USACO:Mother's Milk)