2017
来源:互联网 发布:java装饰设计模式 编辑:程序博客网 时间:2024/04/28 16:21
题目编号:1017
7 4 3<br>4 1 3<br>0 0 0
NO<br>3
AC代码:#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
struct node
{
int bucket[3];
int step;
};
bool matrix[101][101][101];
int bfs(int a,int b,int c)
{
int half,st[3],i,j;;
node cur,temp;
memset(matrix,0,sizeof(matrix));
queue<node>que;
st[0]=a,st[1]=b,st[2]=c;
half=a>>1;
cur.bucket[0]=st[0],cur.bucket[1]=0,cur.bucket[2]=0,cur.step=0;
matrix[a][0][0]=1;
que.push(cur);
while(!que.empty())
{
cur=que.front(),que.pop();
if((cur.bucket[0]==half&&cur.bucket[1]==half)||(cur.bucket[1]==half&&cur.bucket[2]==half)||(cur.bucket[2]==half&&cur.bucket[0]==half))
{
return cur.step;
}
cur.step++;
for(i=0; i<3; i++)
{
if(cur.bucket[i]>0)
for(j=0; j<3; j++)
{
temp=cur;
if(i==j)continue;
if(temp.bucket[i]<=st[j]-temp.bucket[j])
{
temp.bucket[j]+=temp.bucket[i];
temp.bucket[i]=0;
}
else
{
temp.bucket[i]-=st[j]-temp.bucket[j];
temp.bucket[j]=st[j];
}
if(!matrix[temp.bucket[0]][temp.bucket[1]][temp.bucket[2]])
{
matrix[temp.bucket[0]][temp.bucket[1]][temp.bucket[2]]=1;
que.push(temp);
}
}
}
}
return 0;
}
int main()
{
int a,b,c,ans;
while(cin>>a>>b>>c,a||b||c)
{
if(a%2)
{
cout<<"NO"<<endl;
continue;
}
ans=bfs(a,b,c);
if(ans==0)cout<<"NO"<<endl;
else cout<<ans<<endl;
}
return 0;
}
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- 2017
- [线程]——线程基本信息.优先级
- ng-bind
- Android选择通讯录姓名和手机号信息
- 014.php分支语句switch
- [架构]我眼中的Android架构
- 2017
- ng-cloak
- 1090. Highest Price in Supply Chain (25)
- 选择,循环,顺序结构
- OracleClient使用整理
- ng-bind-template
- #define 用法总结
- 前端模块管理器Bower Browserify Component Duo 的差异
- Java 设计模式之Singleton~~