#include <bits/stdc++.h>
using namespace std;
int C[3];
struct Bot
{
int a[3];
};
map<pair<int, int>, bool> M;
queue<pair<Bot, int> > Q;
int ans[100005];
inline void Add(pair<Bot, int> &x)
{
for(int i=0;i<3;i++)
{
if(ans[x.first.a[i]]==-1)ans[x.first.a[i]]=x.second;
}
Q.push(x);
}
void Move(pair<Bot, int> x, int i, int j)
{
int val=min(C[j]-x.first.a[j], x.first.a[i]);
x.first.a[i]-=val;
x.first.a[j]+=val;
if(M[{x.first.a[0]-x.first.a[1], x.first.a[1]-x.first.a[2]}]==false)
{
M[{x.first.a[0]-x.first.a[1], x.first.a[1]-x.first.a[2]}]=true;
x.second++;
Add(x);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin>>C[0]>>C[1]>>C[2];
for(int i=0;i<=C[2];i++)ans[i]=-1;
Bot x;
cin>>x.a[0]>>x.a[1]>>x.a[2];
pair<Bot, int> p={x,0};
M[{x.a[0]-x.a[1], x.a[1]-x.a[2]}]=true;
Add(p);
while(!Q.empty())
{
pair<Bot, int> u=Q.front();
Q.pop();
Move(u, 0, 1);
Move(u, 0, 2);
Move(u, 1, 0);
Move(u, 1, 2);
Move(u, 2, 0);
Move(u, 2, 1);
}
for(int i=0;i<=C[2];i++)cout<<ans[i]<<" ";
cout<<endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <bits/stdc++.h> using namespace std; int C[3]; struct Bot { int a[3]; }; map<pair<int, int>, bool> M; queue<pair<Bot, int> > Q; int ans[100005]; inline void Add(pair<Bot, int> &x) { for(int i=0;i<3;i++) { if(ans[x.first.a[i]]==-1)ans[x.first.a[i]]=x.second; } Q.push(x); } void Move(pair<Bot, int> x, int i, int j) { int val=min(C[j]-x.first.a[j], x.first.a[i]); x.first.a[i]-=val; x.first.a[j]+=val; if(M[{x.first.a[0]-x.first.a[1], x.first.a[1]-x.first.a[2]}]==false) { M[{x.first.a[0]-x.first.a[1], x.first.a[1]-x.first.a[2]}]=true; x.second++; Add(x); } } int main() { ios_base::sync_with_stdio(0); cin>>C[0]>>C[1]>>C[2]; for(int i=0;i<=C[2];i++)ans[i]=-1; Bot x; cin>>x.a[0]>>x.a[1]>>x.a[2]; pair<Bot, int> p={x,0}; M[{x.a[0]-x.a[1], x.a[1]-x.a[2]}]=true; Add(p); while(!Q.empty()) { pair<Bot, int> u=Q.front(); Q.pop(); Move(u, 0, 1); Move(u, 0, 2); Move(u, 1, 0); Move(u, 1, 2); Move(u, 2, 0); Move(u, 2, 1); } for(int i=0;i<=C[2];i++)cout<<ans[i]<<" "; cout<<endl; } |
English