#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define iamspeed ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
int lim[10], t[10], res[100005], g[10], h[10], n, len, zmian;
map<pair<int, pair<int, int> >, bool> mp;
vector<int> G;
queue<vector<int>> V;
int main()
{
iamspeed;
cin >> lim[1] >> lim[2] >> lim[3];
cin >> t[1] >> t[2] >> t[3];
n = lim[3];
for(int i = 0 ; i <= n ; i++)
{
res[i] = INT_MAX;
}
res[t[1]] = res[t[2]] = res[t[3]] = 0;
G.push_back(0); G.push_back(t[1]); G.push_back(t[2]); G.push_back(t[3]);
V.push(G);
while(!V.empty())
{
g[1] = V.front()[1]; g[2] = V.front()[2]; g[3] = V.front()[3]; len = V.front()[0];
V.pop();
res[g[1]] = min(res[g[1]], len);
res[g[2]] = min(res[g[2]], len);
res[g[3]] = min(res[g[3]], len);
for(int i = 1 ; i <= 3 ; i++)
{
for(int j = 1 ; j <= 3 ; j++)
{
if(i != j)
{
h[1] = g[1] ; h[2] = g[2] ; h[3] = g[3];
zmian = min(lim[j] - g[j], g[i]);
h[j] += zmian;
h[i] -= zmian;
if(!mp[make_pair(h[1], make_pair(h[2], h[3]))])
{
mp[make_pair(h[1], make_pair(h[2], h[3]))] = 1;
G.clear();
G.push_back(len + 1); G.push_back(h[1]); G.push_back(h[2]); G.push_back(h[3]);
V.push(G);
}
}
}
}
}
for(int i = 0 ; i <= n ; i++)
{
if(res[i] != INT_MAX) cout << res[i] << " ";
else cout << "-1 ";
}
}
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 | #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define iamspeed ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) int lim[10], t[10], res[100005], g[10], h[10], n, len, zmian; map<pair<int, pair<int, int> >, bool> mp; vector<int> G; queue<vector<int>> V; int main() { iamspeed; cin >> lim[1] >> lim[2] >> lim[3]; cin >> t[1] >> t[2] >> t[3]; n = lim[3]; for(int i = 0 ; i <= n ; i++) { res[i] = INT_MAX; } res[t[1]] = res[t[2]] = res[t[3]] = 0; G.push_back(0); G.push_back(t[1]); G.push_back(t[2]); G.push_back(t[3]); V.push(G); while(!V.empty()) { g[1] = V.front()[1]; g[2] = V.front()[2]; g[3] = V.front()[3]; len = V.front()[0]; V.pop(); res[g[1]] = min(res[g[1]], len); res[g[2]] = min(res[g[2]], len); res[g[3]] = min(res[g[3]], len); for(int i = 1 ; i <= 3 ; i++) { for(int j = 1 ; j <= 3 ; j++) { if(i != j) { h[1] = g[1] ; h[2] = g[2] ; h[3] = g[3]; zmian = min(lim[j] - g[j], g[i]); h[j] += zmian; h[i] -= zmian; if(!mp[make_pair(h[1], make_pair(h[2], h[3]))]) { mp[make_pair(h[1], make_pair(h[2], h[3]))] = 1; G.clear(); G.push_back(len + 1); G.push_back(h[1]); G.push_back(h[2]); G.push_back(h[3]); V.push(G); } } } } } for(int i = 0 ; i <= n ; i++) { if(res[i] != INT_MAX) cout << res[i] << " "; else cout << "-1 "; } } |
English