原题链接:https://www.acwing.com/solution/content/90865/
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N=105,INF=0x3f3f3f3f;
int s,n,m;
struct colo{
int x,y,z;
};
int dist[N][N][N];
int bfs()
{
queue<colo> q;
q.push({s,0,0});
memset(dist,0x3f,sizeof dist);
dist[s][0][0]=0;
while(q.size())
{
auto t=q.front();
q.pop();
if((t.x==t.y&&t.z==0)||(t.x==t.z&&t.y==0)||(t.y==t.z&&t.x==0)){
return dist[t.x][t.y][t.z];
}
//1-2,2-1,1-3,3-1,2-3,3-2
int dx[6]={max(t.x-n+t.y,0),min(s,t.x+t.y),max(t.x-m+t.z,0),min(s,t.x+t.z),t.x,t.x};
int dy[6]={min(n,t.y+t.x),max(0,t.y-s+t.x),t.y,t.y,max(0,t.y-m+t.z),min(n,t.y+t.z)};
int dz[6]={t.z,t.z,min(m,t.z+t.x),max(0,t.z-s+t.x),min(m,t.z+t.y),max(0,t.z-n+t.y)};
for(int i=0;i<6;i++)
{
if(dist[dx[i]][dy[i]][dz[i]]==INF)
{
dist[dx[i]][dy[i]][dz[i]]=dist[t.x][t.y][t.z]+1;
q.push({dx[i],dy[i],dz[i]});
}
}
}
return INF;
}
int main()
{
while(cin>>s>>n>>m,s||n||m)
{
if(s&1) puts("NO");
else {
int t=bfs();
if(t==INF) puts("NO");
else cout<<t<<endl;
}
}
return 0;
}
标签:非常,13,dist,min,int,max,&&,include,可乐
From: https://www.cnblogs.com/linearlearn/p/17288028.html